Curl collection garbled and not to collect PHP
The PHP program is encoded with gbk2312:
$url = "http://www.sina.com.cn";//gbk2312 encoding
$url = "http://www.163.com";//gbk2312 encoding
$url = "http://www.sohu.com";//gbk2312 encoding
$ch = Curl_init ($url);
curl_setopt ($ch, Curlopt_returntransfer, true);//returns the text stream of the obtained output
$ret = curl_exec ($ch);
curl_setopt ($ch, curlopt_timeout, 1);
Curl_close ($ch);
Echo $ret;
?>
In the acquisition of sina.com.cn, is normal, but the acquisition of 163.com is empty, the acquisition of Sohu.com is lost code.
What's going on here? How to solve? What's the matter? Thank you first!!! Not a lot of points, sorry.
------Solution--------------------
Nothing else, I just came to get points. Landlord remember to give full points
$curl =curl_init (' http://www.163.com ');
curl_setopt ($curl, curlopt_returntransfer,1);
curl_setopt ($curl, Curlopt_useragent, ' mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1;. NET CLR 1.1.4322) ');
$html =curl_exec ($curl);
Var_dump ($html);
$curl =curl_init (' http://www.sohu.com ');
curl_setopt ($curl, curlopt_returntransfer,1);
curl_setopt ($curl, Curlopt_useragent, ' mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1;. NET CLR 1.1.4322) ');
$html =curl_exec ($curl);
$html =strstr ($html, ' < ');
$html =gzdecode ($html);
Var_dump ($html);
function Gzdecode ($data) {
$len = strlen ($data);
if ($len < 18
------Solution--------------------
strcmp (substr ($data, 0,2), "\x1f\x8b")) {
return null; Not GZIP format (see RFC 1952)
}
$method = Ord (substr ($data, 2, 1)); Compression method
$flags = Ord (substr ($data, 3, 1)); Flags
if ($flags &! = $flags) {
Reserved bits is set--not allowed by RFC 1952
return null;
}
Note: $mtime may negative (PHP integer limitations)
$mtime = Unpack ("V", substr ($data, bis));
$mtime = $mtime [1];
$XFL = substr ($data, 8, 1);
$os = substr ($data, 8, 1);
$headerlen = 10;
$extralen = 0;
$extra = "";
if ($flags & 4) {
2-byte length prefixed EXTRA data in header
if ($len-$headerlen-2 < 8) {
return false; Invalid format
}
$extralen = Unpack ("V", substr ($data, 8,2));
$extralen = $extralen [1];