Curl picking up garbled and not collecting PHP

Source: Internet
Author: User
Tags rfc unpack
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];
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.