Change default character encoding for PHP files on Centos April 12, 2010
Geek alert! Only read this post if you are massively geek/developer oriented!
A client emailed in this weekend to find out why their recently imported database data was displaying weird symbos for any place of their sites “higher level” characters. We’ve done a lot of character encoding work for our biggest client and feel we know our stuff in this realm. As such we prefer to set up our Apache web servers, and PHP installs, to use the UTF-8 character set. After a little research by us, and the customer, it turned out that their database data was encoded in iso-8859-1 so symbols like á would look like this: ®
Like usual, we instructed the client to insert the directive below into an .htaccess file:
AddCharset ISO-8859-1 .php
But it didn’t work.
After testing on a couple of different servers it turned out that PHP, and only PHP (not Apache), controls encoding on PHP files. This seems like a no-brainer in retrospect, but it had Dave and I confused for a bit. At any rate, this is what one does to override the character set in an .htacccess file for PHP files:
php_value default_charset ISO-8859-1
We’ve added this to our support FAQ for future reference as well.