I'm trying to output the date in Traditional Chinese.
I have the date as a Unix timestamp, ( example: "1467244800" ).
I am doing the following:
<?php
setlocale (LC_TIME, "zh_TW");
echo strftime("%e %B %Y", $timestamp );
?>
What I'm getting output is the Unicode "Undefined" characters:
30 ���� 2016
17 �T�� 2016
18 �Q�G�� 2015
Can anyone tell me what I'm doing wrong?
My HTML headers contain:
<html lang="zh-TW">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
And the rest of my Chinese content on the page is outputting fine. If you view the page source you see:
<span>最新消息</span>
<span class="pipe">18 �Q�G�� 2015</span>
It's only the strftime() dates that appear as "Undefined" characters: ����...
Thanks for looking...
You must probably tell PHP that all strings are UTF-8. E.g.:
Or if the problem is just with this string:
Or if
mb_detect_encoding()
does not work correctly:Before version 7 PHP basically does not know the encoding of the strings. Everything is just an array of 8 bit bytes. Getting the right output encoding sometimes works OK at once, but at other times you have to set everything up by hand.
Locales not only come in different languages, but also different encodings. The default
zh_TW
locale will probably use some Chinese encoding, while what you want is UTF-8. Hence, use the UTF-8 version of the locale:This depends on your specific system and what locales are installed on it. Check that on the command line:
To be more cross-platform compatible, you can try several locales: