Learning php string encoding conversion and determination
This article introduces a piece of code for transcoding and judgment of string encoding in php programming. if you need it, you can take it as a reference. In php, GBK and UTF-8 encoding conversion are often required. for example, json_encode in PHP itself does not support GBK encoding. There are two library functions that support encoding conversion. Generally, the iconv function can be thought of. for example:
However, iconv can only solve the problem of pre-known encoding. if the string encoding is unknown, you need to first detect its encoding. in this case, the mb_string extension library may be used: However, mb_detect_encoding has a hard injury, which often results in inaccurate judgment. You can refer to the following solutions: After obtaining the string encoding information, you can use iconv or mb_convert_encoding for encoding conversion. |