php strftime French characters
The Content-Type header needs to set the code page to UTF-8.
header('Content-Type: text/html; charset=UTF-8');
Since you can't change the header once you've output anything to the page with echo or print make sure you set it early in the page.
The ASCII code page is fully contained in UTF-8 not vice-versa.
Replace the UTF-8 header with the ASCII one and you'll see what happens when the characters aren't included in the current code page.
<?php
header('Content-Type: text/html; charset=UTF-8');
//header('Content-Type: text/html; charset=ASCII');
$myDate = "Feb 23, 2011";
$locale = 'fr_FR.UTF-8';
setlocale(LC_ALL, $locale);
echo strftime('%d %B %Y', strtotime($myDate));
$locale = 'en_US.UTF-8';
setlocale(LC_ALL, $locale);
echo strftime('%d %B %Y', strtotime($myDate));
?>
This seems to be a problem / bug with the strftime
function.
You can solve it using:
$date_string = utf8_encode(strftime('%d %B %Y', strtotime($post->post_date)));
Locales come in different encodings! You are advertising your site as using UTF-8, but strftime
does not return a UTF-8 encoded string, because the locale you chose is not a UTF-8 locale. Check your system what locales you have, e.g.:
$ locale -a | grep fr_FR
fr_FR
fr_FR.ISO8859-1
fr_FR.ISO8859-15
fr_FR.UTF-8
Then choose the UTF-8 variant of your locale, e.g.:
setlocale(LC_ALL, 'fr_FR.UTF-8');
If you do not have a UTF-8 variant of your locale available, either consult the help system of your OS how to install it, or do an encoding conversion in PHP.