David Preston

Musings of an old bloke.

Southport Air Show 2014

Posted about 3 years ago (27 October 2014 6:43 pm) by David Preston

The Red Arrows The Red Arrows

I had a day out at the Southport Air Show a few weeks ago. It was held over a weekend, the Saturday suffering from pretty gloomy weather with low cloud. I went on the Sunday, when conditions were much more suitable.

Here are a few photos.

Join the Discussion

Categories: Out & About

dpreston.com Now Powered by ProcessWire

Posted about 3 years ago (24 October 2014 6:45 pm) by David Preston

After years of neglect, during which time server upgrades and Wordpress awkwardness almost rendered this blog completely inoperable, I finally made the leap to change its backend to ProcessWire.

I first discovered ProcessWire a couple of years ago, and have built several sites with it since, mostly small ones but the odd biggie.

The following ProcessWire modules are in use -

And kinda surprisingly, that's all.

The front end of the site uses a couple of ready made CSS files -

The daft idea originally was to avoid JS as much as possible, but it snuck in all over the place eventually.

It's going to be permanently 'in beta', and used as a testbed where appropriate fun.

Let me know what you think in the comments section.

Join the Discussion

Categories: Web Development

Tags: Processwire

Prime Minister Follows Parody Darth Vader On Twitter

Posted about 6 years ago (25 May 2012 12:00 am) by David Preston

I’m not sure if this is good, bad, cool, uncool or just plain weird. The official Twitter account of the British Prime Minister follows a spoof Darth Vader account!

Well, I suppose Cameron is something of a parody of a Prime Minister anyway, so why not?

Join the Discussion

Categories: Uncategorised

Tidying & Formatting Postal Addresses in PHP

Posted about 6 years ago (8 May 2012 2:50 pm) by David Preston

A couple of times in the course of my job, I've needed to tidy-up user input of postal addresses, usually when importing from an external database into a web application or taking input from a web form. It looks horrible when everything is in upper or lower case. PHP has strtoupper(), strtolower() and ucasewords() functions, but none of these does just what I needed. Googling found a few attempts to solve the same problem, and I've probably pinched bits of code from various places. If I've pinched some of yours, let me know and I'll acknowledge your contribution. Hence the function below.

function address_tidy($text) {
    $text = trim($text);
    $text = str_replace("\\r", "", $text);
    $text = str_replace("\\n", "", $text);
    $words = explode(" ", $text);
    foreach ($words as $word) {
        $word = ucfirst(strtolower($word));
        //Specials like Mac, Mc etc
        $specials = array("Mac", "Mc", "O'");
        foreach ($specials as $special) {
            $pos = stripos($word, $special);
            if (($pos !== false) && ($pos == 0)) {
                $parts = explode($special, $word);
                $word = $special . ucfirst($parts[1]);
        //...but not for some words that begin with "Mac"
        // (make your own mind up about Macintosh, Maclure & Maclaren)
        $specials = array("macken", "macclesfield", "machynlleth");
        if (in_array(strtolower($word), $specials)) {
            $word = ucfirst(strtolower($word));
        //Let"s go lower case on some words
        $specials = array("de", "la", "le", "on", "of", "and", "under", "upon");
        if (in_array(strtolower($word), $specials)) {
            $word = strtolower($word);
    return implode(" ", $words);

Here’s a quick run-down of what it does when you feed it a string…

The first 3 lines just strip white-space from either end of the string and remove any line breaks and newlines.

We then use explode() to break the string into words on space characters and the foreach() loop deals with each word, one at a time.

The first line inside the loop does most of the work, converting the word first to lower case and then capitalising it, which is great for the vast majority of words, but what about Scottish and Irish names? That’s what the next few lines deal with. Essentially, presented with a list of prefixes declared as $specials (which you can add to if needed), we then find any words that begin with those prefixes and capitalise the fragment of word following. Example – the word being processed arrives as ‘Macdonald’, and the code goes through each of the ‘specials’ to see if our word starts with the prefix. It does in the case of ‘Mac’, so we capitalise ‘donald’ and put the two fragments back together as ‘MacDonald’.

But that messes up ‘Macclesfield’, making it ‘MacClesfield’, so the next few lines undo what we just did for another list of ‘specials’, which you can also add to if you wish.

Then we just make some shorter words (are they conjunctions?) into lower case, so you end up with ‘Walton le Dale’ or ‘Stratford upon Avon’.

Then we put the text back together and return it. Easy. Help yourself if you find this function useful. Any links back or other acknowledgements would be more than welcome, but aren't necessary.

Leave a comment if you find any bugs, or you think you can improve my code.

Join the Discussion

Categories: Web Development

Tags: PHP

A Developer’s CMS

Posted about 6 years ago (24 April 2012 6:25 pm) by David Preston

I have used CMSs (Content Management Systems) for years, mainly Joomla, but also others. I don’t consider WordPress a CMS, but that’s just me. Anyhow, I came across a new (to me, anyway) one a few weeks ago that has very quickly become my favourite. It is called ProcessWire, and it is unusual because it has no front end. (The download comes with an example front end, but there is no requirement to use it.) So we PHP and CSS dabblers can have a field day!

All the ProcessWire CMS (or content management framework) does is look after the back end organisation of fields into pages and pages into a hierarchy. It does a great deal more than that but click the link and read more there. Every time I use ProcessWire I find new delights, whether in the way it makes data available for front end display or in the control it gives of data in the back end, and the community, though quite small, is knowledgeable, friendly and helpful. I could go on at great length, but get over there and find out for yourself!

Join the Discussion

Categories: Web Development

Tags: Processwire