自动检测内容是编码进行转换


$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;
}

?>

Popularity: 3%

No Responses to “自动检测内容是编码进行转换”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>