Although the latest PHP5.4 supports JSON Chinese encoding, it uses the JSON_UNESCAPED_UNICODE parameter, for example: json_encode (quot; Chinese quot;, JSON _... although the latest PHP 5.4 supports JSON Chinese encoding, it uses the JSON_UNESCAPED_UNICODE parameter, for example:
Json_encode ("Chinese", JSON_UNESCAPED_UNICODE) for earlier PHP versions, the json encoding of Chinese characters is not escaped.
The interaction between PHP and JavaScript is actually very convenient, and PHP native also provides support for JSON format. Mainly includes two functions: JSON encoding and decoding:
Json_endoce: http://cn.php.net/json_encode
Json_dedoce: http://cn.php.net/json_decodejson_encode
Encode the variable in JSON format and return the value in JSON format, for example:
1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr);?>
After the above code is executed, the output is {"a": 1, "B": 2, "c": 3, "d": 4, "e": 5}
Assume that the data source to be encoded (usually an array) contains Chinese characters. after json_encode processing, unicode encoding is output. the code is as follows:
'Mango station '); echo json_encode ($ arr);?>
The above code is output after execution. the code is as follows:
{"A": "u8292u679Cu5C0Fu7AD9 "}
Unicode processing has been performed at the underlying layer of PHP. if it is not intuitive enough, you can use urlencode and urldecode to bypass the unicode transcoding process. The code is as follows:
$ Arr = array ('a' => urlencode ('Mango Xiaozhan '));
Echo urldecode (json_encode ($ arr); output after the above code is executed: {"a": "mango site "}
Here is a more perfect method:
Permanent link:
Reprint at will! Include the article address.