


PHP code example to simulate get_headers function_PHP tutorial
Jul 21, 2016 pm 03:11 PM
<?php
02 if(!function_exists('get_headers')){
03 function get_headers($url,$format=0){
04 $url=parse_url($url);
05 $end="rnrn";
06 $fp=fsockopen($url['host'],(empty($url['port'])?80:$url['port']),$errno,$errstr,30);
07 if($fp){
08 $out="GET / HTTP/1.1rn";
09 $out.="Host: ".$url['host']."rn";
10 $out.="Connection: Closernrn";
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("/rnrn.*$/",'',$var);
20 $var=explode("rn",$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'));

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development

BitMEX exchange withdrawal rules and advantages and disadvantages

gate official website entrance gate exchange official website

The latest top ten digital currency trading app rankings in 2025

How to trade in TREZOR and what to note

How do you parse and process HTML/XML in PHP?

The latest ranking list of the top ten formal virtual currency trading platforms in 2025
