PHP - 另一种语言的strftime输出是乱码[重复]

This question already has an answer here:

I have this code in PHP to translate dates to their locale

$date = time();
$locale_code = 'en_NZ';
$format_full_date = '%e %B %Y at %l:%M %P'; // 21 August 2013 at 3:26 am

// Set locale
setlocale(LC_ALL, $locale_code);

// Get date
$locale_date =  strftime(lang('format_full_date'), $date);

// Reset locale
setlocale(LC_ALL, 0);

This works fine in en_NZ. The output is something like 21 August 2013 at 8:26 pm

But when I change locale_code to fr_CA, I get outputted 21 ao�t 2013 at 8:26

There are two problems here

  • Why is the French August translation garbled?
  • Why is am/pm not showing?
</div>

I'm guessing strftime outputs in a different encoding than your current Content-Encoding. Make sure they match or do a conversion. utf8_encode/utf8_decode might come in handy.

August in French is août.

my suspicion is that it is to do with unicode encoding. Try this:

setlocale(LC_ALL, $localecode);
echo utf8_encode(strftime(lang('format_full_date'), $date);