php 编程中自动检测内容,然后进行编码转换的函数,供大家学习参考了。
<?php
//自动检测 编码转换
function get_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;
//http://www.jb200.com
//调用示例:get_encoding($data,"GB2312");
}
?>