最新消息:

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

iconv admin 7908浏览 0评论

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

$this->debug_show("客户机命令:".iconv("GBK","UTF-8", $this->in));

上面这行摘自:http://justwinit.cn/post/1057/

最后,修改为如下:

$this->debug_show("客户机命令:".iconv("GBK","utf-8//TRANSLIT//IGNORE", $this->in));

———————————————————————————————————————————————————

读其官方文档 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了!

转载请注明:爱开源 » PHP中Notice: iconv(): Unknown error (84) 的解决办法

您必须 登录 才能发表评论!