自动检测内容中的编码并进行转换的函数
时间:2021-07-01 10:21:17
帮助过:40人阅读
//---示例 - $url = “http://www.163.com”;
- $data = file_get_contents($url);
- $data = my_encoding($data,”utf-8″);
- echo “$data”;
//--函数 - function my_encoding($data,$to)
- {
- $encode_arr = array(‘UTF-8′,’ASCII’,'GBK’,'GB2312′,’BIG5′,’JIS’,'eucjp-win’,’sjis-win’,'EUC-JP’);
- $encoded = mb_detect_encoding($data, $encode_arr);
- $data = mb_convert_encoding($data,$to,$encoded);
- return $data;
- }
?>
|