PHP5.4 make JSON better understand Chinese

Source: Internet
Author: User
We know that when json_encode of PHP is used to process Chinese characters, Chinese characters are encoded and become unreadable, similar to \ u *** format, it also increases the amount of data transmitted to a certain extent. echojson_encode (& quot; Chinese & quot;); // & quot; \ u4e2d \ u6587 & quot; This lets me... "> <LINK

We know that when PHP's json_encode is used to process Chinese characters, Chinese characters are encoded and become unreadable, similar to the "\ u ***" format, it also increases the amount of data transmitted to a certain extent.

Echo json_encode ("Chinese ");

// "\ U4e2d \ u6587"

This makes it a headache for those of us who develop in Tianchao. sometimes they have to write json_encode on their own.

In PHP5.4, this problem was finally solved. Json added a new option: JSON_UNESCAPED_UNICODE, so the name is Unicode, that is, Json does not encode Unicode.

See the following example:

Echo json_encode ("Chinese", JSON_UNESCAPED_UNICODE );

// "Chinese"

How are changes that make everyone happy? Well, of course, Json is added in 5.4: JSON_BIGINT_AS_STRING, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, etc. if you are interested, refer to: json_encode.

However, we still need to remind you that PHP 5.4 is still in the development stage. before the final release, any new features may be adjusted or changed. if you have any suggestions, please feel free to give us feedback and help us make PHP better.

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.