复制代码 代码如下:
<?php
02 if(!function_exists('get_headers')){
03function get_headers($url,$format=0){
04$url=parse_url($url);
05$end="/r/n/r/n";
06$fp=fsockopen($url['host'],(empty($url['port'])?80:$url['port']),$errno,$errstr,30);
07if($fp){
08$out="GET / HTTP/1.1/r/n";
09$out.="Host: ".$url['host']."/r/n";
10$out.="Connection: Close/r/n/r/n";
11$var='';
12fwrite($fp,$out);
13while(!feof($fp)){
14$var.=fgets($fp,1280);
15if(strpos($var,$end))
16break;
17}
18fclose($fp);
19$var=preg_replace("//r/n/r/n.*/$/",'',$var);
20$var=explode("/r/n",$var);
21if($format){
22foreach($var as $i){
23if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts))
24$v[$parts[1]]=$parts[2];
25}
26return $v;
27}else{
28return $var;
29}
30}
31}
32 }
33 echo '<pre>';
34 print_r(get_headers('http://www.vevb.com'));
新闻热点
疑难解答