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

WBOY
Release: 2016-06-01 12:22:55
Original
763 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!