Outputting dates in non-ASCII characters with PHP

后端 未结 2 1842
南笙
南笙 2021-01-22 23:28

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:



        
2条回答
  •  温柔的废话
    2021-01-23 00:07

    You must probably tell PHP that all strings are UTF-8. E.g.:

        mb_internal_encoding('UTF-8');
    

    Or if the problem is just with this string:

        $out = strftime("%e %B %Y", $timestamp);
        echo mb_convert_encoding($out, 'UTF-8', mb_detect_encoding($out));
    

    Or if mb_detect_encoding() does not work correctly:

        $out = strftime("%e %B %Y", $timestamp);
        echo mb_convert_encoding($out, 'UTF-8', 'CNS-11643');
    

    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.

提交回复
热议问题