PHP中Notice: iconv(): Unknown error (84) 的解决办法

jackxiang 2014-10-23 21:20 | |
今天用PHP读取一个接口的数据使用了iconv转换字符编码格式,出现Notice: iconv(): Unknown error (84) :

上面这行摘自:http://jackxiang.com/post/1057/
最后,修改为如下:

———————————————————————————————————————————————————
读其官方文档 http://www.php.net/manual/en/function.iconv.php对参数out_charset的解释:
The output charset.
If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can’t be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character and an E_NOTICE is generated.

大概的意思就是:
如果你加上 //TRANSLIT 到out_charset 的参数后面,意味着如果找不到目标编码,则程序会去找与其相近的编码。如果你加的是//IGNORE,则不会去找相近的编码,而且只要有一个字符是程序无法识别的则将会报错。
根据上面的解释我将代码
iconv('gb2312','utf-8', serialize($storeData));
改为
iconv('gb2312','utf-8//TRANSLIT//IGNORE', serialize($storeData));

这样就ok了!

来自:http://www.tonitech.com/822.html

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/7582/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2014-10-23 21:56
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]