PHP UTF-8 and gb2312 encoding garbled characters

Source: Internet
Author: User

After a while of php + mssql, I feel that mssql does not support encoding very well (in fact, I am still not sure about it), but I have not been eager to change the database, so I have to wait for a while, an error occurred while submitting the data today.

After a while of php + mssql, I feel that mssql does not support encoding very well (in fact, I am still not sure about it), but I have not been eager to change the database, so I have to wait for a while, an error occurred while submitting the data today.

Because the content of the submitted ntext field is large, it is about 220 KB, which leads to my misunderstanding that it is an error caused by the article being too long. I checked the php configuration and found that the support for mssql. textsize in php is already 400 Kb. Why is there an error? After opening the error, we found that it was not a long article, but an error caused by encoding. The error is as follows:

The Code is as follows: Copy code
Notice: iconv () [function. iconv]: Detected an illegal character in input string in ....

The English language is really bad, but I know that the iconv () function has a problem. Google Translate: illegal characters are detected in the input string. Suddenly realized.

Locate the problem on the internet according to the error prompt, that is, add // IGNORE to the second parameter of iconv (), that is, IGNORE the error. The Code is as follows:

The Code is as follows: Copy code
Iconv ("UTF-8", "gbk // IGNORE", $ str );

Test and submit successfully.

Note: The gbk range is larger than that of gb2313, so the error rate of gbk encoding is smaller than that of gb2313.

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.