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

今天在工作的时候读取一个接口的数据使用了iconv转换字符编码格式(iconv(‘gb2312′,’utf-8’, serialize($storeData));)的时候出现了如下错误:

Notice: iconv(): Unknown error (84) 。。。。。。

读其官方文档 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,则不会去找相近的编码,而且只要有一个字符是程序无法识别的则将会报错。

根据上面的解释我将代码

?

1

iconv('gb2312','utf-8', serialize($storeData));

改为 

?

1

iconv('gb2312','utf-8//TRANSLIT//IGNORE', serialize($storeData));

这样就ok了!

第二个参数加上就可以了

fwrite($fp, iconv('UTF-8', 'gbk//TRANSLIT//IGNORE', $content));

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值