1.如果用curl请求网页,多方网页使用了gzip压缩,那么获取的内容将有可能为乱码。
解决方法
$url = 'http://www.du52.com';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");curl_setopt($ch, CURLOPT_ENCODING ,'gzip'); //加入gzip解析$output = curl_exec($ch);$info = curl_getinfo($ch);curl_close($ch);var_dump($info);var_dump($output);
2.如果请求的网页发生了重定向,通过header('Location: du52.com'),那么请求的网页数据有可能为空,即获取不到内容。
解决方法
$url = 'http://www.mkv8.com';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); //加入重定向处理$output = curl_exec($ch);$info = curl_getinfo($ch);curl_close($ch);var_dump($info);var_dump($output);