Home > Backend Development > PHP Tutorial > PHP iconv 函数转gb2312的bug解决方法_php技巧

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

WBOY
Release: 2016-05-17 09:30:18
Original
818 people have browsed it

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就不用作转换了

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