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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:21:35
Original
1050 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就不用作转换了

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template