http抓取页面信息

//1.html
1
2
3
4
5

//1.php
";
//fsockopen(地址,端口,错误码,错误信息,超时) 返回类型
$fh = fsockopen ('127.0.0.1' , 80 ,$errno , $errstr , 5);
//
$req = array(
    'GET /1.html HTTP/1.1',
    'Host: localhost',
    '',
    ''
);
//拆分资源
$req = implode("\n", $req);
//写入资源
fwrite($fh, $req);
//循环读取资源啊
while($row = fread($fh,32)) {
    echo $row;
}
fclose($fh)


?>

页面输出结果如下

HTTP/1.1 200 OK
Date: Sat, 06 Aug 2016 11:50:49 GMT
Server: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/5.5.30
Last-Modified: Sat, 06 Aug 2016 11:33:17 GMT
ETag: "f-539658ca10d41"
Accept-Ranges: bytes
Content-Length: 15
Content-Type: text/html

1
2
3
4
5

你可能感兴趣的:(http抓取页面信息)