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

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

WBOY
WBOY Original
2016-07-21 15:39:43 1030browse

Finally, Huangtian paid off and I found the answer.

This is how it is used on the Internet

Copy the codeThe code is as follows:

$content = iconv("utf-8","gb2312",$content);


This is actually correct. It looks like it is indeed converting utf-8 to gb2312. But in actual operation, it often ends in failure. What is 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 codeThe code is as follows:

$content = iconv("utf-8","gb2312//IGNORE",$content);


It’s very simple, just add //IGNORE after it, just add this ICONV() function ignores errors and continues execution.

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

www.bkjia.com true http: //www.bkjia.com/PHPjc/321499.html TechArticle Finally, 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...
Statement:
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