PHP iconv solve Utf-8 and gb2312 encoding conversion issues

Source: Internet
Author: User

Finally Emperor not bear, the answer or let me find.

It's all on the Internet.

The code is as follows: $content = Iconv ("Utf-8", "gb2312", $content);



In fact, it is also right, looking at the Utf-8 is actually converted into gb2312, but the actual operation of the words, often fail to end, why?

The reason is actually very simple, because any function is the time to execute the error, and unfortunately Iconv (), it is finally error. Now give you the right answer.

The real answer is this.

Copy the code as follows: $content = Iconv ("Utf-8", "Gb2312//ignore", $content);



It's simple, just add a//ignore to the back, plus this can be the iconv () function ignores the error and continues execution.

Similarly, want to change gb2312 as utf-8 as long as write $content = Iconv ("gb2312", "Utf-8//ignore", $content);

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.