The problem of iconv function and mb_convert_encoding function transcoding

Source: Internet
Author: User
Tags translit truncated
These two functions have their own characteristics,
1, iconv speed, natural preference, but he has a disadvantage, if you encounter the character can not be converted, it is truncated from there. This causes the content in the transcoding to be truncated for no reason.
2, the mb_convert_encoding function is less efficient, but he encounters the content that cannot be converted is not truncated, which preserves the integrity of the content to a great extent. But I found that if there were spaces in the content, the converted content would be. symbols, or not perfect enough.

How do I combine these two functions to transcode characters?

My train of thought is this:
It is preferable to use the ICONV function because it is efficient and built-in function. Discuz transcoding function is also preferred to use this function, but his transcoding is not complete, it is necessary to arrange mb_convert_encoding to clean up the mess, the question came, how to judge his transcoding is not complete?


Reply to discussion (solution)

Although the mb_convert_encoding function needs to load the php_mbstring extension
But it's not a built-in function to load.

For unrecognized characters, the ICONV provides two switches for you to choose from, and not to blindly truncate
Translit to replace with similar characters
IGNORE Discard and Continue

Although the mb_convert_encoding function needs to load the php_mbstring extension
But it's not a built-in function to load.

For unrecognized characters, the ICONV provides two switches for you to choose from, and not to blindly truncate
Translit to replace with similar characters
IGNORE Discard and Continue

As if I had added the Ignore function, but some of the content transcoding is still not ideal.
In other words, sometimes with iconv line, mb_convert_encoding not, mb_convert_encoding line, iconv and not

Although the mb_convert_encoding function needs to load the php_mbstring extension
But it's not a built-in function to load.

For unrecognized characters, the ICONV provides two switches for you to choose from, and not to blindly truncate
Translit to replace with similar characters
IGNORE Discard and Continue

Experiment, the ignore may be able to go around the past (before the encounter can not be spared), but the conversion of certain characters, the character is lost.
Like, "?" When the symbol was converted into gb2312, Iconv did not convert, but mb_convert_encoding converted. So the two have advantages and disadvantages, now just how to compare the perfect combination to use.

  • 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.