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

黄舟
Release: 2023-03-07 06:56:02
Original
1713 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!