It's my blog, and I'll write what I like!
25th May 2012

Prime Minister Follows Parody Darth Vader On Twitter

Twitter screenshotI’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?

20th May 2012

Further to my aside about the Denver Posts’s favicon, I finally got round to making my own. And it looks like theirs. But isn’t.

davepreston - 20th May 2012
15th May 2012

Just noticed the Denver Posts‘s favicon is just like my logo. Well, we do have the same initials. And they were probably around before me. So I won’t sue.

davepreston - 15th May 2012
8th May 2012

Tidying & Formatting Postal Addresses in PHP

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.

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

Lines 4, 5 & 6 just strip white-space from either end of the string and remove any line breaks and newlines.

Line 7 breaks the string into words on space characters and the loop from line 8 to line 18 deals with each word, one at a time.

Line 9 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 lines 11-17 deal with. Essentially, presented with a list of prefixes declared as $specials at line 11 (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 at line 12 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 lines 21-24 undo what we just did for another list of ‘specials’, which you can also add to if you wish.

Lines 26-29 just make some shorter words (are they conjunctions?) into lower case, so you and up with ‘Walton le Dale’ or ‘Stratford upon Avon’.

Then we put the text back together and return it at line 31. 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.

27th April 2012

A Developer’s CMS

ProcessWireI 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!

27th March 2012

Apache Basic Authentication Username in Raw Access Logs

Here’s something that might be so blindingly obvious to everyone else in the world that I look like a jerk for talking about it, but I couldn’t find the answer by searching Google, so I’m going to share it anyway.

We are developing a web project at work that I can’t talk about yet, but the boss wanted to email a link and login details (the site is protected by Apache’s Basic Authentication, you know, where a username and password box comes up before you can access a site or directory) to a potential partner. And we wanted to be able to check if they had used the information and visited the site.

Well, after much unsuccessful Googling, I noticed that the logged-in username is right there in the raw access log, just after the IP address of the visitor. So all I needed to do was create a new username/password pair just for them and we can see if they drop by.

28th February 2012


CoincidenceI love coincidences. There was I, making some icons for a website I’m working on at work, when I noticed this one.

The icon is to indicate that somewhere is open all year, and the file size? 365 bytes, naturally.

28th February 2012

Whoops, messing about with the minify settings in W3 Total Cache and broke the CSS. Fixed now.

davepreston - 28th February 2012
24th February 2012

Mystery picture

Mystery picture

This is a bit of a mystery. This old photo is on the wall in my local, the White Bull, in Chorley, but nobody knows where the photo was taken. It’s obviously old, and looks to be of the laying of some tram tracks, but Chorley never had trams, so it isn’t here. Any ideas? [...]

24th February 2012

I can safely say that I’m looking forward to the Carling Cup Final on Sunday as much as I’ve looked forward to a Liverpool game for many a long while.

(And this is also a chance to experiment with different post formats!)

quite a long while ago...
page 1 of 2 »
Follow Me
Facebook Github GooglePlus Twitter
Popular Categories