问:
fsockopen - fputs - fget 后得到网页的内容,其中头部包括了那些headr信息的,请问如何能够把这些信息去掉?
就是诸如
HTTP/1.1 200 OK Date: Tue, 23 Mar 2004 19:29:43 GMT Server: Apache/1.3.22 Set-Cookie: BAIDUID=6E67AA72C34CD67E19FA4F0C8A58C9CB; expires=Tue, 23-Mar-34 19:29:43 GMT; path=/; domain=.baidu.com Cache-Control: max-age=86400 Expires: Wed, 24 Mar 2004 19:29:43 GMT Last-Modified: Wed, 17 Mar 2004 18:05:00 GMT ETag: "3979-11ae-4058934c" Accept-Ranges: bytes Content-Length: 4526 Connection: close Content-Type: text/html
这些东西
______________________________________________________________________________________________
答1:
<?php
$str = '
hello HTTP/1.1 200 OK Date: Tue, 23 Mar 2004 19:29:43 GMT Server: Apache/1.3.22 Set-Cookie: BAIDUID=6E67AA72C34CD67E19FA4F0C8A58C9CB; expires=Tue, 23-Mar-34 19:29:43 GMT; path=/; domain=.baidu.com Cache-Control: max-age=86400 Expires: Wed, 24 Mar 2004 19:29:43 GMT Last-Modified: Wed, 17 Mar 2004 18:05:00 GMT ETag: "3979-11ae-4058934c" Accept-Ranges: bytes Content-Length: 4526 Connection: close Content-Type: text/html
';
$reg = '|HTTP/1.1 200 OK Date: Tue, 23 Mar 2004 19:29:43 GMT Server: Apache/1.3.22 Set-Cookie: BAIDUID=6E67AA72C34CD67E19FA4F0C8A58C9CB; expires=Tue, 23-Mar-34 19:29:43 GMT; path=/; domain=.baidu.com Cache-Control: max-age=86400 Expires: Wed, 24 Mar 2004 19:29:43 GMT Last-Modified: Wed, 17 Mar 2004 18:05:00 GMT ETag: "3979-11ae-4058934c" Accept-Ranges: bytes Content-Length: 4526 Connection: close Content-Type: text/html|';
$abc = preg_replace($reg,"",$str);
echo $abc;
?>
______________________________________________________________________________________________
答2:
先把返回的值放到变量中,设为$text
则
$text = preg_replace("|^.+Content-Type: text/html|","",$text);
______________________________________________________________________________________________
答3:
我前面贴的只是一个例子,但是有些网站返回的header信息不一定是那个样子的,而且也未必是Content-Type: text/html结尾.
如果是那样子就确实比较简单了.
继续求救~~~
curl函数虽然是可以,但是不是系统默认支持的函数库,也不好:(
______________________________________________________________________________________________
答4:
Accept-Ranges: bytes Content-Length: 4526
表示数据体的长度,你自己分析一下
______________________________________________________________________________________________
答5:
to 唠叨
分析content length确实可以
不过有些网站可能用了类似 ob_start() ... 之类的函数
它的header返回的信息是 Transfer-Encoding: chunked ,而没有content length的!
______________________________________________________________________________________________
答6:
还有一个奇怪的问题是,如果对方网站真的用了ob_start() ... 之类的函数
get回来的网页内容每一小段中间会自己插入一个 1000 在里面,估计是1k个字节打印一个1000出来(有兴趣的网友可以试试).
不过这个东西把原来的网页排版都给搅乱了~~!
______________________________________________________________________________________________
答7:
如上所说,高手快点来
______________________________________________________________________________________________
答8:
顶
______________________________________________________________________________________________
答9:
没人帮忙解答吗?
______________________________________________________________________________________________
答10:
顶
来源:http://study.qqcf.com/web/723/281740.htm
fsockopen - fputs - fget 后得到网页的内容,其中头部包括了那些headr信息的,请问如何能够把这些信息去掉?
就是诸如
HTTP/1.1 200 OK Date: Tue, 23 Mar 2004 19:29:43 GMT Server: Apache/1.3.22 Set-Cookie: BAIDUID=6E67AA72C34CD67E19FA4F0C8A58C9CB; expires=Tue, 23-Mar-34 19:29:43 GMT; path=/; domain=.baidu.com Cache-Control: max-age=86400 Expires: Wed, 24 Mar 2004 19:29:43 GMT Last-Modified: Wed, 17 Mar 2004 18:05:00 GMT ETag: "3979-11ae-4058934c" Accept-Ranges: bytes Content-Length: 4526 Connection: close Content-Type: text/html
这些东西
______________________________________________________________________________________________
答1:
<?php
$str = '
hello HTTP/1.1 200 OK Date: Tue, 23 Mar 2004 19:29:43 GMT Server: Apache/1.3.22 Set-Cookie: BAIDUID=6E67AA72C34CD67E19FA4F0C8A58C9CB; expires=Tue, 23-Mar-34 19:29:43 GMT; path=/; domain=.baidu.com Cache-Control: max-age=86400 Expires: Wed, 24 Mar 2004 19:29:43 GMT Last-Modified: Wed, 17 Mar 2004 18:05:00 GMT ETag: "3979-11ae-4058934c" Accept-Ranges: bytes Content-Length: 4526 Connection: close Content-Type: text/html
';
$reg = '|HTTP/1.1 200 OK Date: Tue, 23 Mar 2004 19:29:43 GMT Server: Apache/1.3.22 Set-Cookie: BAIDUID=6E67AA72C34CD67E19FA4F0C8A58C9CB; expires=Tue, 23-Mar-34 19:29:43 GMT; path=/; domain=.baidu.com Cache-Control: max-age=86400 Expires: Wed, 24 Mar 2004 19:29:43 GMT Last-Modified: Wed, 17 Mar 2004 18:05:00 GMT ETag: "3979-11ae-4058934c" Accept-Ranges: bytes Content-Length: 4526 Connection: close Content-Type: text/html|';
$abc = preg_replace($reg,"",$str);
echo $abc;
?>
______________________________________________________________________________________________
答2:
先把返回的值放到变量中,设为$text
则
$text = preg_replace("|^.+Content-Type: text/html|","",$text);
______________________________________________________________________________________________
答3:
我前面贴的只是一个例子,但是有些网站返回的header信息不一定是那个样子的,而且也未必是Content-Type: text/html结尾.
如果是那样子就确实比较简单了.
继续求救~~~
curl函数虽然是可以,但是不是系统默认支持的函数库,也不好:(
______________________________________________________________________________________________
答4:
Accept-Ranges: bytes Content-Length: 4526
表示数据体的长度,你自己分析一下
______________________________________________________________________________________________
答5:
to 唠叨
分析content length确实可以
不过有些网站可能用了类似 ob_start() ... 之类的函数
它的header返回的信息是 Transfer-Encoding: chunked ,而没有content length的!
______________________________________________________________________________________________
答6:
还有一个奇怪的问题是,如果对方网站真的用了ob_start() ... 之类的函数
get回来的网页内容每一小段中间会自己插入一个 1000 在里面,估计是1k个字节打印一个1000出来(有兴趣的网友可以试试).
不过这个东西把原来的网页排版都给搅乱了~~!
______________________________________________________________________________________________
答7:
如上所说,高手快点来
______________________________________________________________________________________________
答8:
顶
______________________________________________________________________________________________
答9:
没人帮忙解答吗?
______________________________________________________________________________________________
答10:
顶
来源:http://study.qqcf.com/web/723/281740.htm
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/4880/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表