Home > Backend Development > PHP Tutorial > The problem of garbled code conversion between PHP utf-8 and gb2312 encoding_PHP tutorial

The problem of garbled code conversion between PHP utf-8 and gb2312 encoding_PHP tutorial

WBOY
Release: 2016-07-13 10:56:04
Original
1133 people have browsed it

After using php + mssql for a while, I feel that mssql’s support for encoding is not very good (actually I am not sure yet), but I haven’t had the time to change the database urgently, so I can only make do with it, and I am submitting data again today. An error occurred.

After using php + mssql for a while, I feel that mssql’s support for encoding is not very good (actually I am not sure yet), but I haven’t had the time to change the database urgently, so I can only make do with it, and I am submitting data again today. An error occurred.

Since the submitted ntext field contains a lot of content, about 220 KB, I misunderstood it and thought it was an error caused by the article being too long. When I looked at the php configuration, I found that php’s support for mssql.textsize is already at 400 K. Why is there still an error? After turning on the error, I discovered that it was not the article that was too long, but an error caused by the encoding. The error is as follows:

 代码如下 复制代码
Notice: iconv() [function.iconv]: Detected an illegal character in input string in...。

My English is really bad, I just know that there is something wrong with the iconv() function. Google Translate said that illegal characters were detected in the input string. A sudden realization.

Go to the Internet to find a solution to the problem based on the error message, which is to add //IGNORE to the second parameter of iconv(), which means to ignore the error. The code is as follows:

 代码如下 复制代码
iconv("utf-8", "gbk//IGNORE", $str);

Tested and submitted successfully.

Note: Netizen experience shows that the range of gbk is larger than gb2313, so the error rate of encoding with gbk is smaller than that of gb2313.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632194.htmlTechArticleAfter using php + mssql for a while, I feel that mssql’s support for coding is not very good (in fact, I am still not sure about it) (La), but it’s not time to change the database urgently, so I can only make do with it, today...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template