Home  >  Article  >  Backend Development  >  Detailed introduction to Chinese characters that are not unicode encoded when PHP outputs json data

Detailed introduction to Chinese characters that are not unicode encoded when PHP outputs json data

黄舟
黄舟Original
2017-03-28 10:09:401676browse

Today when writing the APIinterface, I converted the PHP array into json, but there is a rule that unicode cannot be used Encoding

Tried several methods:

If PHP is 5.4 or above, you can directly use the JSON_UNESCAPED_UNICODE parameter

json_encode('Chinese test',JSON_UNESCAPED_UNICODE);

This method String is feasible, but array is not feasible (to be verified)

2. Urlencode the string in the array, then convert the array json_encode into json, and finally urldecode

Note: urlencode() and urldecode() convert Chinese characters into hexadecimal and combine strings according to certain rules to achieve character encoding and decoding to ensure the character integrity during URL data transmission. Completeness and Compatibility

The above is the detailed content of Detailed introduction to Chinese characters that are not unicode encoded when PHP outputs json data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn