Iconv function and mb_convert_encoding function transcoding problems

Source: Internet
Author: User
The iconv function and the mb_convert_encoding function have different transcoding features. 1. iconv is fast and naturally preferred. However, it has some disadvantages. if you encounter characters that cannot be converted, it is truncated from there. This causes content to be truncated without reason during transcoding. 2. problems with the mb_convert iconv function and the mb_convert_encoding function transcoding
These two functions have their own characteristics,
1. iconv is fast and naturally preferred, but it has a disadvantage. if you encounter a character that cannot be converted, it will be truncated from there. This causes content to be truncated without reason during transcoding.
2. the efficiency of the mb_convert_encoding function is relatively low, but the unconvertible content will not be truncated, which largely retains the content integrity. But I found that, for example, if there is space in the content, there will be converted content? Symbol, still not perfect.

How can we use these two functions to transcode the characters?

My idea is as follows:
The iconv function is preferred, because it is highly efficient and is a built-in function. Discuz's transcoding function also gives priority to this function. However, when transcoding is incomplete, it is necessary to arrange mb_convert_encoding to clean up the mess. The question is, how can we determine whether transcoding is incomplete?
------ Solution --------------------
Although the mb_convert_encoding function needs to load the php_mbstring extension
But once loaded, it cannot be said that it is not a built-in function.

For unidentifiable characters, iconv provides two switches for you to choose from, rather than simply truncation.
// Transcoder is replaced by similar characters
// IGNORE discards and continues

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.