Php converts u5c0fu533au7eff garbled characters to Chinese characters

Source: Internet
Author: User
Tags json

The code is as follows:

\ U5c0f \ u533a \ u7eff \ u5316 \ u5f88 \ Alibaba \ u9519 |||\ Alibaba \ u4ec0 \ u4e48 \ u65f6 \ u5019 \ Alibaba \ u7684 ||| \ Users \ Users \ u4ea4 \ u623f \ u4e86 | \ u548c \ u683c \ u6797 \ u4e91 \ u5885 \ u79bb \ u5f97 \ Users \ users | \ u5730 \ Users

Can anyone understand the above code? I guess no one is there. I know it's json, so take a piece and test it.

The code is as follows: Copy code

Echo json_decode ('u683c \ u8fd8 \ u4e0d \ u9519 ');

No input is found. Later we thought this is not a standard json. We can use an array to convert it.

The code is as follows: Copy code

$ Array = array ('u683c \ u8fd8 \ u4e0d \ u9519 ');
Echo json_encode ($ array );

The result is:

["U683c \ u8fd8 \ u4e0d \ u9519"]

This is not data in standard json format. I will parse it later.

The code is as follows: Copy code

$ Array = json_decode ('["\ u4e8c \ u671f \ u4ec0 \ u4e48 \ u65f6 \ u5019 \ u4ea4 \ u623f \ u7684"]');

Print_r ($ array );

(
[0] => bang ??? {€ ?? Why ?? Hey? Cross ??
)

It's garbled. I guess this is Encoding. I know that the json conversion encoding is uft8, and my page is gbk. I found the iconv function at that time.

The code is as follows: Copy code

$ Array = json_decode ('["\ u4e8c \ u671f \ u4ec0 \ u4e48 \ u65f6 \ u5019 \ u4ea4 \ u623f \ u7684"]');

Echo iconv ('utf-8', 'gbk', $ array [0]);

The result is:

When will the second phase be handed over?

In this way, garbled characters are successfully converted into Chinese characters. Please give it a try.

Site original tutorial: Reprinted with the source of http://www.111cn.net

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.