Home > Article > Backend Development > PHP character encoding conversion problem
For example: the web page uses gbk encoding, the string uses utf-8 encoding, convert the characters to Web page display encoding.
Summary: It is recommended to use the mb_convert_encoding function, which has no iconv conversion character error problem. Convert the encoding of the string to UTF-8. If you know the encoding of the original string, you can use the iconv function that everyone is familiar with. But now you don’t know the encoding of the original string. It may be GBK, or it may be UTF-8, so you cannot use this method. It would be great if you could get the string encoding type, or have an encoding conversion function that automatically recognizes the original string encoding. It turns out that the mb_convert_encoding function is the function that can automatically identify the original string encoding. However, during use, it was found that some Chinese characters in GBK were converted into garbled characters. Later I found the is_utf8 function in the PHP manual, and then combined with the iconv function, the problem was solved. Encoding conversion function used:
|