Validate a UK postcode

You’ve probably seen this before, if not a thousand times, but here’s a simple function to check the format of a UK postcode.

function valid_uk_postcode($postcode)
{
    return (preg_match('/^([A-PR-UWYZ][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {0,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/i', $postcode)) ?
        true : false;
}
Did you like this? Share it:

HTTP status codes

Quite often I find myself having to send a HTTP status code in the PHP I’m writing. This typically comes down to usually a ‘Forbidden’, ‘No Content’ or a redirect. The trouble is, I usually can’t remember the exact code of text used for the slightly more obscure codes, or at least the ones I don’t use often… Well, even for the ones I use often, if truth be told!

So I put them all in the following function which you may find useful, too.

Continue reading “HTTP status codes”

Did you like this? Share it:

CafePress random product update

A small update is required to the CafePress box class – the one that shows a random product from your CafePress store. This is needed because there have been some additional updates to the HTML on the CafePress side, so the regular expression in the class needs updating. It’s very easy; just change line 174 for the following:

$this->cpPattern = '.*?(.*?)
\$([^< ]*)';
Did you like this? Share it:

Same height for elements

Surely this is easy, right? Just set the height property in your css. Well, yes and no. That’s all well and good if you know what height the elements are going to be, but quite often you might be pulling information out of a database in to the elements and you don’t know how big that information is going to be. You can’t use the overflow because that’s not the designer’s concept. No; they want three boxes on screen that all have the same height so they’re all nice and ordered and symmetrical.

Continue reading “Same height for elements”

Did you like this? Share it:

First post!

Hello, friend, and welcome to my new blog!

Currently there is not much to see here because I’m in the process of moving all of my projects from my other site, php.amnuts.com, to here. If you want to get any of the classes of view the forums then it’s best head on over to the other site. Eventually, on this site I will have documentation and examples for all of the code, plus I’ll also be able to post up snippets, highlights and bug fixes much easier. And that can only be a good thing, right?

As this is so far a rather pitiful excuse for a first post (but it is almost 1am, so forgive me!) I thought I’d list some of those “can’t live without” programs and extensions I use for my development or just in my day-to-day computer use. Please bare in mind that I generally use a Windows-based system and so most of the applications I mention are likely to be for that system.

So, in no particular order…

Continue reading “First post!”

Did you like this? Share it: