Unicode Encoding

published on March 5th, 2008 · more from the blog →

Ok, so recently i've been making all my web pages support unicode character sets, one of the tasks is ensuring all output is encoded in utf-8. Anyway to make a long story short, using the ob_get_contents() function i showed you a few posts ago, gives you output in whatever character set the file is saved as, and no matter what you do you cant get the blasted thing to display as utf-8... so there are a few methods of fixing this...

My first attempt being php's iconv() function to convert all the output into utf-8, however, this is just pants and you'd have to detect what format its in in the first place in order to recode it...

The other (and better) approach is just to ensure that all your pages are encoded in utf-8 to start with, with the IDE I use (Coda) you can set the default file encoding in the preferences, and i'm sure many other editors give you the same options.

Magic.