今天要导出四月份的数据,但是在导出的时候出现了一个问题,在导出数据的最后出现了一堆代码,而且数据导出不完整
然后在本地服务器测试的时候发现却是可以正常导出的
比较发现自己把本地的警告提示等级调成了(E_ALL& ~E_NOTICE & ~E_STRICT)
而在服务器上的是(E_ALL)
之后调取php notice,发现错误是 iconv(): Unknown error (84)
很迷茫不知道是什么错误,百度一下
string iconv ( string $in_charset , string $out_charset , string $str )
将字符串 str 从 in_charset 转换编码到 out_charset。
参数
in_charset:输入的字符集。
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()函数转码的时候某个字符不能被目标字符所表示
这时候就需要iconv()函数第二个参数的//TRANSLIT、//IGNORE两个值了
于是我将代码:
$row[$key] = iconv('utf-8', 'gbk', $value);
改为:
PHP
$row[$key] = iconv('utf-8', 'gbk//TRANSLIT//IGNORE', $value);