Headaches with PHP's setlocale() and UTF-8
13th March 2010
I've been working on a German language site that uses PHP's date() function to output formatted dates in various places. I had set character encoding to UTF-8 - the only sensible choice header('Content-Type: text/html; charset=UTF-8');
but then using setlocale
setlocale(LC_ALL, 'de_DE');
rendered month names where an umlaut was necessary with the dreaded � the secret, not explicitly mentioned in the PHP manual was:
setlocale(LC_ALL, 'de_DE.UTF-8');
If you want the locale to be used in date formatting, use strfromtime() rather than date().
Tagged: PHP I18n
Comments and corrections to @edvanbeinum