php5.4 Json_unescaped_unicode to make JSON more literate in Chinese

Source: Internet
Author: User
Tags json

When using PHP's Json_encode to process Chinese, Chinese will be coded, become unreadable, resemble "u***" format, and increase the amount of data transferred to some extent.

The code is as follows Copy Code

<?php
Echo Json_encode ("Chinese"); Output: "u4e2du6587"


This let us do development in the celestial students, is very headache, sometimes also have to write their own json_encode.

In PHP5.4, the problem was finally resolved, and JSON added an option: Json_unescaped_unicode, hence the name incredible, which means that JSON does not encode UNICODE.

Look at the following example:

The code is as follows Copy Code

<?php
Echo Json_encode ("Chinese", json_unescaped_unicode); Output: "Chinese"


What, is it a change that makes everyone happy?

Oh, of course, JSON also added in 5.4: json_bigint_as_string, Json_pretty_print, json_unescaped_slashes, etc.

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.