How to solve the php iso 8859 1 garbled problem

藏色散人
Release: 2023-03-05 20:58:02
Original
3855 people have browsed it

Solution to phpiso 88591 garbled code: first use iconv to decode to "ISO-8859-1"; then use the "iconv("GB18030", "UTF-8", $str)); method to convert "GB18030"; finally restore it to "UTF-8" to solve the garbled problem.

How to solve the php iso 8859 1 garbled problem

Recommendation: "PHP Video Tutorial"

Solving the problem of garbled characters in UTF documents

In the Unicode state of the browser, I saw such a garbled code. I tried to use PHP to decode it, but it failed... However, a simple file encoding conversion was successful. The steps are as follows:

Keep the content in Western (ISO8859-1) format

Open it with a browser, set the encoding to GB2312, and complete

The problem is this, if my file must Using UTF8 encoding, how to decode this garbled code?

The garbled content is:

'²»ÖªµÀÕâÑùµÄÖ÷»ú¡£'
Copy after login

PHP extension iconv is used for encoding conversion.

The transcoding method is:

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

The answer is not that simple. I just tried it. The correct solution is like this

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

First decode to ISO-8859- 1. However, it is still garbled in this state, so it needs to be converted to GB18030, and then restored to UTF-8 (the encoding that matches the file where it is located).

The above is the detailed content of How to solve the php iso 8859 1 garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template