Php converts u5c0fu533au7eff garbled characters to Chinese characters

Source: Internet
Author: User
Today, the company is working on a function to connect data to the app. the other party transfers the data after the json escape, but it is not a standard json formatted data, we directly use json_decode to enter the original character. let's take a look at the solution of the year. Code such... today, the company is working on a function to connect data to the app. the other party transfers the data after the json escape, but it is not a standard json formatted data, we directly use json_decode to enter the original character. let's take a look at the solution of the year.

The code is as follows:

\u5c0f\u533a\u7eff\u5316\u5f88\u4e0d\u9519|||\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684|||\u4e8c\u671f\u4ea4\u623f\u4e86|||\u548c\u683c\u6797\u4e91\u5885\u79bb\u5f97\u5f88\u8fd1|||\u5730\u7406\u4f4d\u7f6e

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

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.

$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.

$array = json_decode('["\u4e8c\u671f\u4ec0\u4e48\u65f6\u5019\u4ea4\u623f\u7684"]');
Print_r ($ array); ([0] => bang ??? {€ ?? Why ?? Hey? Cross ??) Yes

Garbled code. I guess this is a coding problem. I know that the json conversion code is uft8, and my page is gbk. I found the iconv function at that time.

$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.phprm.com

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.