Are you still using iconv for php transcoding functions ?. When using PHP to process strings, we often encounter character encoding conversion problems. Have you ever encountered iconv conversion failure? When I found the problem, I searched the internet and found that iconv was originally using PHP to process strings. we often encountered character encoding conversion problems. Have you ever encountered iconv conversion failure?
When I found the problem, I searched the internet and found that iconv had a bug. some uncommon words could not be converted. of course, when I configured the second parameter, I could slightly make up for the default defect, it cannot be converted but is truncated. the usage is as follows:
Iconv ("UTF-8", "GB2312 // IGNORE", $ data );
In this case, when the conversion of uncommon words fails, it will ignore the failure and continue to convert the following content. this is a solution to the problem, but to ensure the conversion success rate, we can use another conversion function (mb_convert_encoding). according to the information on the Internet, this function is not very efficient. In addition, this function can omit the third parameter and automatically identify content encoding, however, it is best not to use it, which affects efficiency. Note that the order of mb_convert_encoding and iconv parameters is different.
Two functions are provided for simple usage:
Iconv
StringIconv(String$ In_charset, String$ Out_charset, String$ Str)
First parameter: Original Content encoding
Second parameter: Target encoding
Third parameter: string to be converted
Function return string
$ Instr = 'test ';
// GBK to UTF-8
$ Outstr = iconv ('gbk', 'utf-8', $ instr );
?>
Mb_convert_encodingstring mb_convert_encoding (string $ str, string $ to_encoding [, mixed $ from_encoding]) first parameter: string to be processed second parameter: Target encoding third parameter: content original encoding
?>
We recommend that you use mb_convert_encoding to avoid transcoding problems.
Why? When I found the problem, I searched the internet and found that iconv had B...