PHP converts uncode to utf8, and one line of code solves the problem.

Source: Internet
Author: User
In many cases, we can see unicode-encoded text, such as u6d3bu52a8u63a5u53e3. Although the program will recognize it, it is inconvenient for human eyes to read it. Many people write many conversion functions on the Internet, however, the solution with a line of PHP code is: $ str {success: true, msg: u6d3bu52a8u6

Unicode-encoded text, such as \ u6d3b \ u52a8 \ u63a5 \ u53e3, can be seen in many occasions. Although the program knows it, it is inconvenient for the human eyes to read it, many people write a lot of conversion functions on the network, but one is more bloated, and finally found a solution with a line of PHP code: $ str = '{"success": true, "msg": "\ u6d3b \ u52a8 \ u6

In many cases, we can see unicode-encoded text, such as "\ u6d3b \ u52a8 \ u63a5 \ u53e3". Although the program will recognize it, it is inconvenient for human eyes to read it, many people write a lot of conversion functions on the network, but one is more bloated, and finally found a solution with a line of PHP code:

$ Str = '{"success": true, "msg": "\ u6d3b \ u52a8 \ u63a5 \ u53e3 "}'; echo $ str = preg_replace ("# \\\ u ([0-9a-f] +) # ie", "iconv ('ucs-2', 'utf-8 ', pack ('h4 ',' \ 1 ') ", $ str );



If the server is self-written, you can use the following methods to solve php5.4 or later:

Echo json_encode ("Chinese character", JSON_UNESCAPED_UNICODE );

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.