Php5.2.4iconv function Transcoder sometimes unreliable php version & nbsp; 5.2.4 problem: improper truncation by byte during file string transcoding, such as $ str "Company"; by default, it is encoded in UTF-8 $ strSimple_Util_String :: msubstr ($ str, 4); truncate php 5.2.4 iconv function Transcoder by byte 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.