21,891
社区成员
发帖
与我相关
我的任务
分享<?php
function getFileSize($url){
$url = parse_url($url);
if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1\r\n");
fputs($fp,"Host:$url[host]\r\n\r\n");
while(!feof($fp)){
$tmp = fgets($fp);
if(trim($tmp) == ''){
break;
}else if(preg_match('/(Content-Length.*)/si',$tmp,$arr)){
return trim($arr[1]);
}
}
return null;
}else{
return null;
}
}
echo getFileSize("http://www.baidu.com/")
?>GET / HTTP/1.1
Host:www.baidu.com
HTTP/1.1 200 OK
Date: Sat, 21 Nov 2009 09:17:58 GMT
Server: BWS/1.0
Content-Length: 3520
Content-Type: text/html;charset=gb2312
Cache-Control: private
Expires: Sat, 21 Nov 2009 09:17:58 GMT
Set-Cookie: BAIDUID=7B14CFF75A3DC12D4A590E53760BBA2F:FG=1; expires=Sat, 21-Nov-39 09:17:58 GMT; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "
<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>.................. </title><style>body{margin:4px 0}p{margin:0;padding:0}img{border:0}td,p,#u{font-size:12px}#b,#u,#l td,a{font-family:arial}#kw{font:16px Verdana;height:1.78em;padding-top:2px}#b{height:30px;padding-top:4px}#b,#b a{color:#77c}#u{padding-right:10px;line-height:19px;text-align:right;margin:0 0 3px !important;margin:0 0 10px}#sb{height:2em;width:5.6em}#km{height:50px}#l{margin:0 0 5px 15px}#l td{padding-left:107px}p,table{width:650px;border:0}#l td,#sb,#km{font-size:14px}#l a,#l b{margin-right:1.14em}a{color:#00c}a:active{color:#f60}#hp{position:absolu
te;margin-left:6px}#lg{margin:-26px 0 -44px}#lk{width:auto;line-height:18px;vertical-align:top}form{position:relative;z-index:9}</style></head>
<body><div id=u><a href=http://passport.baidu.com/?login&tpl=mn>....</a></div><center><img src=http://www.baidu.com/img/baidu_logo.gif width=270 height=129 usemap="#mp" id=lg><br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a
onclick=s(this) href=http://news.baidu.com>.. ..</a><b>.. ..</b><a onclick=s(this) href=http://tieba.baidu.com>.. ..</a><a onclick=s(this) href=http://zhidao.baidu.com>.. ..</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>.. ..</a><a onclick=s(this) href=http://video.baidu.com>.. ..</a></div></td></tr></table>
<table cellpadding=0 cellspacing=0 style="margin-left:15px"><tr valign=top><td style="height:62px;padding-left:92px" nowrap><form name=f action=s><input type=text name=wd id=kw size=42 maxlength=100> <input type=submit value=........ id=sb><span id=hp><a href=/gaoji/preferences.html>....</a><br><a href=/gaoji/advanced.html>....</a></span></form></td></tr></table>
<p id=km><a href=http://hi.baidu.com>....</a> <a href=http://www.hao123.com>hao123</a> | <a href=/more/>....<span style="font-family:....">>></span></a></p>
<p style=height:60px><table cellpadding=0 cellspacing=0 id=lk><tr><td></td></tr></ta
ble></p>
<p style=height:30px><a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com')" href=http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com>..............</a></p><p style=height:14px><a href=http://e.baidu.com>............</a> | <a href=http://top.baidu.com>..........</a> | <a href=http://home.baidu.com>........</a> | <a href=ht
tp://ir.baidu.com>About Baidu</a></p><p id=b>©2009 Baidu <a href=http://www.baidu.com/duty/>..............</a> <a href=http://www.miibeian.gov.cn target=_blank>..ICP..030173..</a> <img src=http://gimg.baidu.com/img/gs.gif></p><map name=mp><area shape=rect coords="43,22,227,91" href=http://hi.baidu.com/baidu/ target=_blank title="........ ........"></map></center></body>
<script>var w=document.f.wd;function s(o){if(w.value.length>0){var h=o.href;var q=encodeURIComponent(w.value);if(h.indexOf("q=")!=-1){o.href=h.replace(new RegExp("q=[^&$]*"),"q="+q)}else{o.href+="?q="+q}}};(function(){if(new RegExp("q=([^&]+)").test(location.search)){w.value=decodeURIComponent(RegExp.$1)}})();if(navigator.cookieEnabled&&!/sug?=0/.test(document.cookie)){document.write('<script src=http://www.baidu.com/js/bdsug.js?v=1.1.0.3><\/script>')};if(window.attachEvent){window.attachEvent("onload",function(){w.focus();})}else{window.addEventListener('load',function(){w.focus()},true)};window.onunload=function(){};</script></html><!--
0e94a8fd6438cdd2-->