Are you still using iconv for php transcoding functions? _ PHP Tutorial

Source: Internet
Author: User
Are you still using iconv for php transcoding functions ?. When using PHP to process strings, we often encounter character encoding conversion problems. Have you ever encountered iconv conversion failure? When I found the problem, I searched the internet and found that iconv was originally using PHP to process strings. we often encountered character encoding conversion problems. Have you ever encountered iconv conversion failure?

When I found the problem, I searched the internet and found that iconv had a bug. some uncommon words could not be converted. of course, when I configured the second parameter, I could slightly make up for the default defect, it cannot be converted but is truncated. the usage is as follows:

Iconv ("UTF-8", "GB2312 // IGNORE", $ data );

In this case, when the conversion of uncommon words fails, it will ignore the failure and continue to convert the following content. this is a solution to the problem, but to ensure the conversion success rate, we can use another conversion function (mb_convert_encoding). according to the information on the Internet, this function is not very efficient. In addition, this function can omit the third parameter and automatically identify content encoding, however, it is best not to use it, which affects efficiency. Note that the order of mb_convert_encoding and iconv parameters is different.

Two functions are provided for simple usage:

Iconv

StringIconv(String$ In_charset, String$ Out_charset, String$ Str)

First parameter: Original Content encoding

Second parameter: Target encoding

Third parameter: string to be converted

Function return string

$ Instr = 'test ';

// GBK to UTF-8

$ Outstr = iconv ('gbk', 'utf-8', $ instr );

?>

Mb_convert_encodingstring mb_convert_encoding (string $ str, string $ to_encoding [, mixed $ from_encoding]) first parameter: string to be processed second parameter: Target encoding third parameter: content original encoding
 
?>

We recommend that you use mb_convert_encoding to avoid transcoding problems.

Why? When I found the problem, I searched the internet and found that iconv had B...

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.