Everything I know about Internationalisation I learnt from Eurovision

Well okay, that’s not quite true. As I’m sure most of you are aware, last saturday was [Eurovision][1] and like many people I watched it with friends (and with a large drink in my hand). What I did that most other people didn’t do, however, was [live review it on TheTenWordReview.com][2].

It was this act of live reviewing that made me realise that not everything was at peace in the land of ten word reviews - various characters were becoming ‘funky’ and splitting themselves up into two when being displayed on screen. Of course, you know what’s coming next.

That’s right. I’d forgotten to tell the site to display itself as UTF-8. A quick <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> fixed that on my development box, but for some reason the live site was still screwed. Thankfully, telling PHP to output header('Content-Type: text/html; charset=utf-8'); at the top of each page got the live site realising that it should be displaying as UTF-8.

But the fun didn’t stop there. Throughout the site I was using PHP’s htmlentities() function to output any user input. Unfortunately, in a few places I forgot to pass in the optional encoding variable. You guessed it, not doing this caused output to be screwy too, since it meant that once text had been entityfied nice single UTF-8 characters were being transformed into yucky multiple ASCII ones. Oops. A quick find and replace sorted that out.

My final problem with those fancy schmancy european characters came from my database connection. Although I’d set the tables up to store everything as UTF-8, apparently the connections which were being set up from PHP to the MySQL server were being created as ‘latin1’. Not what was wanted. Since I have no ability to fiddle with the MySQL setup on the site’s server I ended up sending the query ‘SET NAMES utf8’ at the beginning of each connection to kick start it into thinking in UTF-8.

Thankfully, after all that I was able to get on with the important task of reviewing camp songs from across Europe. Frankly, I think that Ukraine should have won, and that it was terribly unfortunate that The UK came on after them. Ah well.

permalink | View blog reactions

other relevant pages

about wwm

workingwith.me.uk is a resource for web developers created by Neil Crosby, a web developer who lives and works in London, England. More about the site.

Neil Crosby now blogs at The Code Train and also runs NeilCrosby.com, The Ten Word Review and Everything is Rubbish.