string mb_detect_encoding ( string $str [, mixed $encoding_list = mb_detect_order() [, bool $strict = false ]] )
Detects character encoding in string str.
$url = "https://www.taobao.com";
$res = preg_match('/^(http|https|ftp):\/\/(.*)\.(.*)/i',$url);
if(!$res){
echo "地址不合法";exit;
}
//注:https情况,服务器需要修改PHP.ini
//extension=php_openssl.dll
//allow_url_include = On
$tmp = file_get_contents($url);
if(!$tmp){
exit('地址不正确,请检查网页是否存在!');
}
$encode = mb_detect_encoding($tmp,array('ASCII','GB2312','GBK','UTF-8'));
echo $encode;