Home>Article>Backend Development> How to solve the php iso 8859 1 garbled problem
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.
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:
'²»ÖªµÀÕâÑùµÄÖ÷»ú¡£'
PHP extension iconv is used for encoding conversion.
The transcoding method is:
$text = iconv("ISO-8859-1", "UTF-8", $text)
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));
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!