Convert PHPgb2312 to UTF-8 without using iconv, this unreliable iconv ("GB2312", "UTF-8 // IGNORE", $ str );
It is easy to lose words and unstable. if there is no "// IGNORE", it will not be displayed after an error.
Are there other feasible methods?
Reply to discussion (solution)
Try
Mb_convert_encoding
Generally, GBK is used instead of gb2312. there are too few Chinese characters encoded in gb2312.
Charset = gb2312 is used on the webpage. In fact, the browser still calls GBK, so do not mistakenly think that gb2312 can display most Chinese characters.
Impossible! The entire gb2312 is contained in UTF-8, and it is impossible to lose words.
You throw the word because you have processed the gbk character as gb2312.
Try
Mb_convert_encoding
Not feasible.
Php implements mutual conversion between UTF-8 and gb2312 encoding
Php does not use the iconv library for gb2312 and UTF-8 encoding conversion functions
We hope that the above two articles will help you solve your current problems.
Not easy to use .. On the fifth floor
You 'd better post the text.
For example, in MSSQL ",
If iconv ("GB2312", "UTF-8", $ str );
The output is: "XXX Jin"
Iconv ("GB2312", "UTF-8 // IGNORE", $ str );
The output is: "XXX Jin {xx address of the park"
I checked iconv online and found a small BUG. A single character is lost.
$ Str = "XXX Jin Huiyuan address ";
Echo iconv ('gb2312', 'utf-8', $ str); // address of a certain jinhuiyuan
Echo iconv ('gbk', 'utf-8', $ str); // address of a certain jinhuiyuan
No problem
If there is a problem in your environment, you can only say that your php version is too low.
For example, in MSSQL ",
If iconv ("GB2312", "UTF-8", $ str );
The output is: "XXX Jin"
Iconv ("GB2312", "UTF-8 // IGNORE", $ str );
The output is: "XXX Jin {xx address of the park"
I checked iconv online and found a small BUG. A single character is lost.
$ Str = "XX Jin Huiyuan xx address"; echo iconv ("GB2312", "UTF-8", $ str); echo iconv ("GB2312", "UTF-8 // IGNORE ", $ str );
My side is normal.
Of course.
I saved this address in the database of GB2312 at the address of a XXX Jin Huiyuan. The problem occurred when I read it.
XX Jin Huiyuan xx address is bg2312 code stored outside
The currently processed page is utf-8. pay attention to this difference.