SiteKickr Web Development

Forgotten PHP, ColdFusion & Test driving a new cloud host

Server Side

PHP has anonymous functions too (and they make sense in WordPress development)

If you do enough front-end development, you might forget that JavaScript isn’t the only language that supports anonymous functions. PHP allows them as well and they really make sense in some areas of web development.

Take the well known WordPress functions.php file for example. This script typically becomes a dumping ground for all kinds of functions that clutter up the global namespace.

By declaring very small, single-use functions anonymously, we avoid the adding another function name. Here’s an example that I recently used in a page template. I simply needed to add a class name to the body tag. Defining a function name was not necessary.

add_filter('body_class', function($classes, $class) {
   $classes[] = 'home';
   return $classes; 
});

 

Paragraph formatting user content

This is probably even less cool than it sounds, but I thought it was worth sharing. In any given web project that I’m involved in, there’s at least one form that accepts multi-line text from a user and stores it to a database. This text is often served up on a given page in the website.

Given that it’s user provided content, it’s gonna need a good scrubbing. I used to simply wrap the content in one big paragraph tag, then replace line breaks with <br>s. But, I thought it might be nice to actually serve up proper paragraph tags instead of simply <br>ing everything.

Using ColdFusion code as an example, this little one-liner will regex replace a group of line breaks into a single </p><p>:

<p>#REReplace(myText, "[#chr(10)#]+", "</p><p>", "ALL")#</p>

 

Webmaster

Cloud Hosting

I’m still mentally affected by the fact that one of the servers I remote into on a weekly basis failed a couple months ago. The single hard drive suffered a crash and the company was forced to shell out big bucks for a data recovery service.

I’ve since moved many of my sites over to a new Codero Cloud server, nothing but praise so far. But, there are cheaper options out there, and I thought I’d give one a try for some of my less “uptime-critical” endeavors.

Just today I signed up for a 2GB Togglebox cloud instance. What’s kinda cool about it is that I can create as many virtual servers within my cloud instance as I like. And, unlike Codero, I can have multiple IPs on a single instance. I’ll report back on my trials with Togglebox but, so far so good. And the price is fantastic.

The control panel is also very complete, something greatly lacking with Codero’s Cloud services.

That all being said, Codero has been extremely reliable for me over the past 10 years. They may not have all the bells and whistles, but sometimes those bells and whistles leave more room for error.