Monthly Archives: June 2009

Dynamically Named Static Method Calls

Something that is being added in PHP 5.3.0 but is sorely missed in current versions is the ability to call a static class method from variables. It is something that is occasionally very useful (e.g. you have a validation class triggering other regional classes) and is already possible with standard class calls. Thankfully it’s very easy to simulate with eval…

Asynchronous cURL Requests

A possibly underused technique available to PHP developers is the ability to spawn a background PHP script without JavaScript. All you need to do this is the cURL library and a few lines of code. Let me explain, suppose you have a script that is going to take minutes (or longer) to run, you don’t want to sit looking at a blank screen, and your users certainly won’t! In this kind of scenario you can separate out that logic to a background file and leave your view free for other things, perhaps to query the database to see how the background process is doing?

Spin Text For SEO – A PHP Spinner

I recently had an SEO expert give us a few hours of his time to provide some suggestions to compliment our SEO strategy. One of the techniques that he introduced I was so impressed with (due to it’s utter simplicity) that I am kicking myself for not thinking of it before! Basically, if you have ‘doorway’ pages into your site (e.g. you have pages for ‘Cambridge Widgets’ and ‘Preston Widgets’ and alike) and want them to be dynamically generated, from the same content, but not to suffer horrible duplicate content penalties, you can use a ‘spinning’ function to generate contextually similar, different, content. The original concept is here, but I have enhanced it a bit to better suit my needs.

Validate E-mail Addresses

I know this is a topic with 1001 solutions, but I still get asked for an e-mail validation check from time to time, so here is one that I have used in the past. It’s a cut above average as it allows very basic validation, confirmation of a valid domain ending or even performs an MX record check to ensure that a mail server is at least set up for the domain in question.

Convert URLs to Links in a String

Another common function that I get asked for is the ability to highlight links in a block of text that contains urls, but doesn’t have them within anchor tags. So, to stop me hearing this question and advising people to ‘use Google’ here is a function that will do this. It very likely isn’t bullet proof (and isn’t the most elegant thing I’ve ever seen), but will hopefully be either good enough or provide inspiration for your own solution.

PHP Function to Apply Multiple Others…

From time to time I’ll post little snippets of code that I have been asked for, or see requested again and again. One such request is the ability to apply a set of transformations to text (or whatever) again and again without writing them out each time.

Journey to the End of the Night

The city spreads out before you. Rushing from point to point, lit by slow strobe lights through dark streets. Stumbling into situations for a stranger’s signature. Fleeing unknown pursuers, breathing hard, admiring the landscape and the multitude of worlds hidden in it.

Removing WordPress Autosave and Drafts

Another problem with Wordpress that has almost instantly begun to bug me is the autosave ‘feature’ of Wordpress. I simply don’t want it on! There doesn’t seem to be an option, and despite downloading a plugin to fix it ‘Disable Revisions and Autosave’ (by Exper) this doesn’t seem to work anymore in WP 2.8, damn.

Fixing WordPress Code Formatting

As one of my tasks to make this basic blog I had to learn a little about Wordpress (2.71), just enough to get it skinned and get writing. I very quickly came across what I can only assume must be an extremely common problem that expert users face when writing their posts / pages in this excellent platform, text formatting. At first I thought I was doing something wrong. When I swapped between the Visual and HTML views I seemed to lose any <p> tags (and likely countless others) and when I actually viewed the site’s source I had gained <br /> tags… I did what most people do and hit Google for quick solutions, but I couldn’t find anything acceptable.