Home  >  Article  >  php教程  >  PHP iconv 函数转gb2312的bug解决方法

PHP iconv 函数转gb2312的bug解决方法

WBOY
WBOYOriginal
2016-06-13 12:21:35987browse

iconv( "UTF-8", "gb2312//IGNORE" , $FormValues['a'])

ignore的意思是忽略转换时的错误,发现iconv在转换字符"—"到gb2312时会出错,如果没有ignore参数,所有该字符后面的字符串都无法被保存。

另外mb_convert_encoding没有这个bug,所以最好的写法是:

mb_convert_encoding($FormValues['a'], "gb2312", "UTF-8");

但是需要先enable mbstring 扩展库。

也可以把mysql数据库的collation设成utf-8就不用作转换了

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