Collect website content, stop at how many lines! How to Operate!

Source: Internet
Author: User
function Get_content_by_socket ($url) {$url = eregi_replace (' ^http://', ', $url); $temp = explode ('/', $url); $host = array _shift ($temp); $url = ". Implode ('/', $temp); $temp = Explode (': ', $host); $host = $temp [0]; $port = Isset ($temp [1])?   $temp [1]: 80;//echo $url;//echo $host; $fp = Fsockopen ($host, or Die ("Open").     $url. "Failed"); $header = "GET/". $url. "     Http/1.1\r\n ";     $header. = "Accept: */*\r\n";    $header. = "accept-language:zh-cn\r\n";    $header. = "Accept-encoding:gzip, deflate\r\n"; $header. = "If-modified-since:tue, Apr 07:56:03 GMT;     Length=2235\r\n "; $header. = "user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;     GTB6.4) \ r \ n "; $header. = "Host:". $host. " \ r \ n "; $header. = "referer:http://video.baidu.com/v?word=11&ct=301989888&rn=20&pn=0&db=0&s=0& Fbl=800\r\n ";     Fputs ($content, "Referer: $domainrn");//Forged part $header. = "connection:keep-alive\r\n"; $header. = "cookie:baiduid=5f96971273579588527a980f307e8b7a:fg=1\r\n\r\n ";     $header. = "connection:close\r\n\r\n";     Fwrite ($fp, $header);     while (!feof ($fp)) {$contents. = fgets ($fp, 8192);     } fclose ($FP); return $contents;  }


Take this function and for example

As long as the 10th line is read, the following will not take the direct end of the output content! So take what you want, save time resources!
Or just read to the custom which field
Can it be achieved?


Reply to discussion (solution)

$i = 0;
while (!eof ($f) and $i <10) {
xxxx
$i + +;
}

  • 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.