Home > Backend Development > PHP Tutorial > PHP iconv solves the problem of utf-8 and gb2312 encoding conversion_PHP tutorial

PHP iconv solves the problem of utf-8 and gb2312 encoding conversion_PHP tutorial

WBOY
Release: 2016-07-21 15:39:30
Original
957 people have browsed it

Finally, Huangtian paid off and I found the answer.

This is how it is used on the Internet

Copy the code The code is as follows:
$content = iconv("utf- 8","gb2312",$content);


This is actually correct. It looks like it is converting utf-8 to gb2312, but in actual operation, it is often run as It failed. What's the reason?

The reason is actually very simple, because any function will have an execution error, and unfortunately iconv(); will eventually cause an error. Now give you the correct answer.

The real answer is this

Copy code The code is as follows:
$content = iconv(" utf-8","gb2312//IGNORE",$content);


It’s very simple, just add //IGNORE after it, and adding this can be ignored by the ICONV() function Error, continue execution.

Similarly, to change gb2312 to utf-8, just write $content = iconv("gb2312","utf-8//IGNORE",$content);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321562.htmlTechArticleFinally, Huangtian paid off and I found the answer. The copy code used on the Internet is as follows: $content = iconv("utf-8","gb2312",$content); This is actually the same as...
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