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 + +;
}