Phputf-8 conversion gb2312 string truncated solution _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Solution to phputf-8 conversion gb2312 string truncated. Iconv (UTF-8, gb2312ignore, $ data) ignore directly means to ignore the conversion error. if the ignore parameter is not specified, all strings after this character cannot be iconv ("UTF-8", "gb2312 // ignore", $ data)
Ignore directly means ignore. in this case, the conversion error is ignored. without the ignore parameter, all strings after this character cannot be saved.

Conv is not the default function in the php Tutorial, but also the default installed module. Installation is required.
For Windows + php, you can modify php. ini file, remove ";" Before extension = php_iconv.dll, and copy the iconv under your original php installation file. dll to your winnt/system32


String iconv (string $ in_charset, string $ out_charset, string $ str)

When using this function for string encoding conversion, note that if UTF-8 is converted to gb2312, the string may be truncated.

You can solve this problem by using the following methods:

$ Str = iconv ('utf-8', "gb2312 // transcoder", file_get_contents ($ filepath ));

That is, add the red part in the second parameter to indicate that if the character matching the source encoding cannot be found in the target encoding, a similar character will be selected for conversion.


You can also use the: // ignore parameter to ignore characters that cannot be converted.

Http://www.bkjia.com/PHPjc/632331.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632331.htmlTechArticleiconv (UTF-8, gb2312 // ignore, $ data) the direct meaning of ignore is to ignore the error during conversion here, if there is no ignore parameter, all strings after this character cannot be protected...

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.