Differences between PHPiconv and mb_convert_encoding

Source: Internet
Author: User
PHPiconv and mb_convert_encoding differences PHP often uses the iconv function in character transcoding, but encountered a problem in a transcoding; example: $ str Today weather-fine; $ striconv (UTF-8, GBK, $ str,); after transcoding, $ str is clear only today. find the manual and find that the second parameter of iconv can be added to the differences between iconv and mb_convert_encoding of PHP.

PHP often uses the iconv function in character transcoding, but encountered a problem in a certain transcoding;

Example:

$ Str = 'weather today-Clear ';

$ Str = iconv ('utf-8', 'gbk', $ str ,);

After transcoding, $ str is only 'Weather is fine today '. find the manual and find that two suffixes can be added to the second parameter of iconv,

?

? // Transcoder automatically converts a character that cannot be directly converted into one or more similar characters,

? // IGNORE ignores the characters that cannot be converted. by default, it is truncated from the first invalid character.

?

Usage:

1. it is found that iconv will encounter an error when converting the character "-" to gb2312. if the ignore parameter is not available, all strings after this character cannot be saved. In any case, the "-" cannot be converted successfully or output. In addition, mb_convert_encoding does not have this bug.

2. mb_convert_encoding can specify multiple input encodings, which are automatically identified based on the content, but the execution efficiency is much lower than iconv;

3. generally, iconv is used. the mb_convert_encoding function is used only when the encoding of the original encoding cannot be determined or The iconv cannot be displayed normally after conversion.

Note: To use mb_convert_encoding, you need to enable this extension in php. ini.

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.