How to solve the Garbled text in UTF?

Source: Internet
Author: User
In the Unicode state in the browser, I see such a garbled code. I tried to use PHP for decoding and failed... but the simple file encoding conversion, it is successful, the step is like this: Keep the content in the Western (ISO8859-1) format open with a browser, set the encoding to gb2312... in the Unicode state in the browser, I see such a garbled code. I tried to use PHP for decoding and failed... however, simple file encoding conversion is successful. The steps are as follows:

  1. Keep content in Western (ISO8859-1) Format

  2. Open it in the browser and set the encoding to GB2312.

The problem is that if my file must be UTF-8 encoded, how can I decode the Garbled text?

The garbled content is: '2» öª µà Õ â n {µäö÷» ú¡ £'

Reply content:

In the Unicode state in the browser, I see such a garbled code. I tried to use PHP for decoding and failed... however, simple file encoding conversion is successful. The steps are as follows:

  1. Keep content in Western (ISO8859-1) Format

  2. Open it in the browser and set the encoding to GB2312.

The problem is that if my file must be UTF-8 encoded, how can I decode the Garbled text?

The garbled content is: '2» öª µà Õ â n {µäö÷» ú¡ £'

PHPExtensioniconvIs used for encoding conversion.
The transcoding method is as follows:

$text = iconv("ISO-8859-1", "UTF-8", $text)

The answer is not that simple. I just tried it. The correct solution is as follows:

var_dump($str = iconv("UTF-8", "ISO-8859-1", '²»ÖªµÀÕâÑùµÄÖ÷»ú¡£'));var_dump($str = iconv("GB18030", "UTF-8", $str));

First to decode as a ISO-8859-1, but this state is still garbled, so you have to convert to GB18030, and then restore to the UTF-8 (with the file where the matching encoding ).

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.