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.