我想通过mb_detect_encoding()函数动态获取某个字符的编码集,再通过iconv进行编码转换,但是mb_detect_encoding()判断的编码类型不准,导致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 回答
- 1 回答
- 0 关注
- 632 浏览
添加回答
举报
0/150
提交
取消