php 模拟get_headers函数的代码示例
2013-04-27 00:00
645 查看
<?php 02 if(!function_exists('get_headers')){ 03 function 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); 07 if($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=''; 12 fwrite($fp,$out); 13 while(!feof($fp)){ 14 $var.=fgets($fp,1280); 15 if(strpos($var,$end)) 16 break; 17 } 18 fclose($fp); 19 $var=preg_replace("/\r\n\r\n.*\$/",'',$var); 20 $var=explode("\r\n",$var); 21 if($format){ 22 foreach($var as $i){ 23 if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts)) 24 $v[$parts[1]]=$parts[2]; 25 } 26 return $v; 27 }else{ 28 return $var; 29 } 30 } 31 } 32 } 33 echo '<pre>'; 34 print_r(get_headers('http://www.jb51.net'));
相关文章推荐
- php 模拟get_headers函数的代码示例
- php中用socket模拟http中post或者get提交数据的示例代码
- php中用socket模拟http中post或者get提交数据的示例代码
- [PHP代码] 用php的fsocket模拟get提交 模拟post提交表单
- php 模拟POST|GET操作实现代码
- php发送get、post请求的6种方法代码示例
- php模拟get提交 字符串截取 字符串替换 示例源码
- PHP读取文件内容后清空文件示例代码
- php模拟post行为代码总结(POST方式不是绝对安全)
- php文件重命名下载代码示例
- php模拟post上传图片实现代码
- PHP API接口必备之输出json格式数据示例代码
- php数值转换时间及时间转换数值代码示例
- PHPExcel下载(从数据库获取数据)示例代码
- php cookie 登录验证示例代码
- PHP CURL模拟GET及POST函数代码
- PHP与javascript实现变量交互的示例代码
- php生成短网址示例代码
- php 论坛采集程序 模拟登陆,抓取页面 实现代码