我想通過mb_detect_encoding()函數(shù)動(dòng)態(tài)獲取某個(gè)字符的編碼集,再通過iconv進(jìn)行編碼轉(zhuǎn)換,但是mb_detect_encoding()判斷的編碼類型不準(zhǔn),導(dǎo)致iconv()失效或亂碼。//片段if (is_string($k)) { $encoding = getEncoding($k); $k = iconv($encoding, "utf-8", $k);
}//獲取編碼集function getEncoding($data)
{
return mb_detect_encoding($data, array("ASCII","GB2312","GBK",'BIG5','UTF-8'));
}//測試$k = "哈哈";$encoding = getEncoding($k);
var_dump($encoding,$k);$k = iconv($encoding, "utf-8", $k);
var_dump(getEncoding($k),$k);exit;//輸出:string(5) "CP936" string(6) "哈哈" string(5) "CP936" string(9) "鍝堝搱"
- 1 回答
- 0 關(guān)注
- 651 瀏覽
添加回答
舉報(bào)
0/150
提交
取消