Php5.2.4iconv function transcoder is sometimes unreliable in php & nbsp; 5.2.4 problem: improper truncation by byte during file string transcoding, for example, $ str = "Company "; // The default UTF-php 5.2.4 iconv function transcoder is sometimes unreliable
Php version 5.2.4
Problem: improper truncation by byte during file string transcoding
For example
$ Str = "Company"; // The default code is $ str = Simple_Util_String: msubstr ($ str, 4); // extract the first 4 bytes by byte, the original string has 6 bytes $ str. = "adfadsfasdfadsfasdf"; // concatenate the following string (after the next step, these characters disappear) $ str = iconv ("UTF-8", "GBK // transcoder ", $ str); // transcoding, conversion of unknown strings
During this step, the "Company"'s "company" word code is incomplete, iconv does not know, but iconv does not transcription, but does not cut off. As a result, the string after $ str is not converted successfully, and "adfadsfasdfadsfasdf" is lost. This is dangerous in some commercial products, especially statistical systems.
Solution:
Change the second iconv parameter.
$ Str = iconv ("UTF-8", "GBK // IGNORE", $ str );
Conclusion: iconv transcoder is not reliable. it may also be truncated if you encounter a string that you don't know or cannot be rewritten. The insurance method is IGNORE.