Php5.2.4iconv function Transcoder sometimes unreliable

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.