今天在工作的时候读取一个接口的数据使用了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 |
|
改为
1 |
|
这样就ok了!
第二个参数加上就可以了
fwrite($fp, iconv('UTF-8', 'gbk//TRANSLIT//IGNORE', $content));