Iconv and mb_convert_encoding in PHP

Source: Internet
Author: User

Iconv is not the default function of PHP, but also the default installed module. Installation is required.

Modify PHP in windows. INI file, remove ";" before extension = php_iconv.dll, and copy the iconv under your original PHP installation file. DLL to your winnt/system32.

In Linux, you can add one more item -- With-iconv to configure by using static installation. phpinfo shows the iconv items.

String iconv (string in_charset, string out_charset, string Str)
Note: In addition to specifying the encoding to be converted, you can also add two suffixes: // Transcoder and // ignore, // 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, the result is truncated from the first invalid character.

String mb_convert_encoding (string STR, string to_encoding [, mixed from_encoding])
Enable mbstring extension Library first, and remove the extension library before extension = php_mbstring.dll in PHP. ini.
Mb_convert_encoding can specify multiple input encodings, which are automatically identified based on the content.

Note that:

1. iconv will encounter an error when converting characters "-" To gb2312. Without the ignore parameter, all strings after this character cannot be saved. mb_convert_encoding does not have this bug.

2. The execution efficiency of mb_convert_encoding is much lower than that of iconv. It is used only when the iconv conversion fails to display normally.

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.