When using PHP json_encode to handle Chinese, Chinese will be encoded, become unreadable, similar to the "\u***" format, if you want Chinese characters do not transcode, here are three ways
1. Upgrade PHP, in PHP5.4, the problem is finally resolved, JSON added an option: Json_unescaped_unicode, so the name Incredibles, that is, JSON do not encode UNICODE.
1 <? PHP 2 3 Echo json_encode ("Chinese", json_unescaped_unicode); 4 5 // "Chinese"
2. UrlEncode the Chinese characters first and then use the Json_encode,json_encode again after using the UrlDecode to decode, so that the encoded JSON array of Chinese characters will not appear Unicode encoding.
1 $array=Array(2' Test ' =UrlEncode("I am a test")3 );4 5 $array= Json_encode ($array);6 7 Echo UrlDecode($array);8 9 //{"Test": "I am a Test"}
3. Decode the Unicode code and decode the function as follows:
function decodeunicode ($str) { returnpreg_replace_callback('/\\ \\u ([0-9a-f]{4})/I ', create_function (' $matches ', ' return Mb_convert_ Encoding (Pack ("h*", $matches [1]), "UTF-8", "ucs-2be"); ), $str);}
4. Example
$arr Array (' name1 ': "Chinese", ' name2 ': ' Abc12 '); $jsonstr = Decodeunicode (Json_encode ($arr));
PHP json_encode Chinese Unicode transcoding problem