Home  >  Article  >  Backend Development  >  PHP iconv function solves the problem of utf-8 and gb2312 encoding conversion

PHP iconv function solves the problem of utf-8 and gb2312 encoding conversion

WBOY
WBOYOriginal
2016-07-25 08:53:55834browse
  1. $content = iconv("utf-8","gb2312",$content);
Copy the code

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 very simple, because any function will have an execution error, and unfortunately iconv(); will eventually have an error.

Correct approach:

  1. $content = iconv("utf-8","gb2312//ignore",$content);
Copy the code

Just add a //ignore after it, add this The iconv() function can ignore the error and continue execution.

Similarly, if you want to change gb2312 to utf-8, just write $content = iconv("gb2312","utf-8//ignore",$content);



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