Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-25 08:53:55
Original
916 people have browsed it
  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);



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