Introduction to unicode encoding for Chinese characters when PHP outputs json data

Source: Internet
Author: User
During writing and API interfaces today, PHP arrays are converted to json, but there is a rule that unicode encoding cannot be used. during writing and API operations today, PHP arrays are converted to json, however, there is a rule that unicode encoding is not supported.

I tried several methods:

If PHP is more than 5.4, you can directly use the JSON_UNESCAPED_UNICODE parameter.

Json_encode ('Chinese test', JSON_UNESCAPED_UNICODE );

This method is feasible for strings, but the array is not feasible (to be verified)

2. urlencode the string in the array, convert the json_encode of the array to json, and then perform urldecode.

Note: urlencode () and urldecode () convert Chinese characters to hexadecimal notation and combine strings according to certain rules to implement character encoding and decoding, ensure character integrity and compatibility during URL data transmission

The above method does avoid unicode encoding for Chinese characters, but I still failed to pass the test at the end of the interface. Instead, I can use the normal json_encode to avoid mistakes, I will continue my research in the future ·····

The above is the detailed description of the unicode encoding method not used in Chinese when PHP outputs json data. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.