PHP iconv(): Unknown error (84)

今天要導出四月份的數據,可是在導出的時候出現了一個問題,在導出數據的最後出現了一堆代碼,並且數據導出不完整php

而後在本地服務器測試的時候發現倒是能夠正常導出的服務器

比較發現本身把本地的警告提示等級調成了(E_ALL& ~E_NOTICE & ~E_STRICT)app

而在服務器上的是(E_ALL)函數

以後調取php notice,發現錯誤是 iconv(): Unknown error (84)測試

很迷茫不知道是什麼錯誤,百度一下編碼

string iconv ( string $in_charset , string $out_charset , string $str )
將字符串 str 從 in_charset 轉換編碼到 out_charset。code

參數
in_charset:輸入的字符集。
out_charset:輸出的字符集。utf-8

查看官方文檔文檔

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);
相關文章
相關標籤/搜索