sih
(sih)
注册会员

初级会员
UID 62637
精华
0
积分 151
帖子 97
金钱 151 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-12-21
状态 离线
|
[广告]: q
m
求助:Socket获取的数据如何处理?
函数:
<?php function get($url) { $url = eregi_replace('^http://', '', $url); $temp = explode('/', $url); $host = array_shift($temp); $path = '/'.implode('/', $temp); $temp = explode(':', $host); $host = $temp[0]; $port = isset($temp[1]) ? $temp[1] : 80;
$fp = @fsockopen($host, $port, $errno, $errstr, 30); if ($fp) { @fputs($fp, "GET $path HTTP/1.1rn"); @fputs($fp, "Host: $hostrn"); @fputs($fp, "Accept: */*rn"); @fputs($fp, "Referer: [url]http://$host/[/url]rn"); @fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)rn"); @fputs($fp, "Connection: Closernrn"); }
$Content = ''; while ($str = @fread($fp, 4096)) $Content .= $str; @fclose($fp);
return $Content; } ?> 然后获取回来HTTP头、正文,还多出来一些不明数据?
HTTP/1.1 200 OK
Date: Thu, 03 Apr 2008 06:05:19 GMT
Server: Apache
Content-Disposition: attachment; filename="5342.py"
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain
129(或2cf等,可变)
正文正文正文……
0
该如何把正文分离出来呢?
[ 本帖最后由 sih 于 2008-4-3 02:35 PM 编辑 ]
|
|