php通过socket获取网页内容的简单示例
程序员文章站
2022-05-15 23:01:21
...
php通过socket获取网页内容的简单示例,请看下面代码:
$url='www.scutephp.com';
$fp=fsockopen($url,80,&$errno,&$errstr,10);
if(!$fp){
echo "$errstr ($errno)
\n";
}else{
fputs($fp,"GET / HTTP/1.0\nHost: ".$url."\n\n");
while(!feof($fp)){
echo fgets($fp,128);
}
fclose($fp);
}