Home Backend Development PHP Tutorial PHP code example to simulate get_headers function_PHP tutorial

PHP code example to simulate get_headers function_PHP tutorial

Jul 21, 2016 pm 03:11 PM
exists function g get headers php code function copy simulation of Example

复制代码 代码如下:

<?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'));

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/326962.htmlTechArticle复制代码 代码如下: ?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[...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

BitMEX exchange withdrawal rules and advantages and disadvantages BitMEX exchange withdrawal rules and advantages and disadvantages Feb 21, 2025 pm 10:48 PM

BitMEX exchange withdrawal rules and advantages and disadvantages

gate official website entrance gate exchange official website gate official website entrance gate exchange official website Feb 19, 2025 pm 03:03 PM

gate official website entrance gate exchange official website

The latest top ten digital currency trading app rankings in 2025 The latest top ten digital currency trading app rankings in 2025 Feb 27, 2025 pm 06:24 PM

The latest top ten digital currency trading app rankings in 2025

How to trade in TREZOR and what to note How to trade in TREZOR and what to note Feb 21, 2025 pm 10:30 PM

How to trade in TREZOR and what to note

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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 The latest ranking list of the top ten formal virtual currency trading platforms in 2025 Mar 05, 2025 pm 08:21 PM

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

See all articles