Home > Backend Development > PHP Tutorial > PHP 解决utf-8和gb2312编码转换问题_PHP

PHP 解决utf-8和gb2312编码转换问题_PHP

WBOY
Release: 2016-06-01 12:19:35
Original
1096 people have browsed it

终于皇天不负有心人,答案还是让我找到了。

网上的都是这样用的

复制代码 代码如下:
$content = iconv("utf-8","gb2312",$content);


这样做其实也对着了,看着确实是把utf-8转化为gb2312了,但是实际运行的话,往往都是以失败告终的,原因呢?

原因实际上也很简单,因为任何的函数都是执行错误的时候,同时很不幸的是iconv();就很终于出现错误。现在给你正确的答案。

真正的答案是这样的

复制代码 代码如下:
$content = iconv("utf-8","gb2312//IGNORE",$content);


很简单的,只要后面加上一个//IGNORE就行,加上这个就可以是ICONV()函数忽略错误,继续执行。

同理,要像把gb2312换为utf-8只要写上$content = iconv("gb2312","utf-8//IGNORE",$content);就行

Related labels:
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