当前位置: 移动技术网 > IT编程>开发语言>PHP > php中get_headers函数的作用及用法的详细介绍

php中get_headers函数的作用及用法的详细介绍

2019年04月13日  | 移动技术网IT编程  | 我要评论

get_headers() 是php系统级函数,他返回一个包含有服务器响应一个 http 请求所发送的标头的数组。如果失败则返回 false 并发出一条 e_warning 级别的错误信息(可用来判断远程文件是否存在)。

函数定义

array get_headers ( string $url [, int $format = 0 ] )

参数

url 目标 url

format 如果将可选的 format 参数设为 1,则 get_headers() 会解析相应的信息并设定数组的键名。

示例

<?php
$url='http://www.phpernote.com';
print_r(get_headers($url));
print_r(get_headers($url,1));
?>

以上例程的输出类似于:

array
(
    [0] => http/1.1 200 ok
    [1] => date: sat, 29 may 2004 12:28:13 gmt
    [2] => server: apache/1.3.27 (unix)  (red-hat/linux)
    [3] => last-modified: wed, 08 jan 2003 23:11:55 gmt
    [4] => etag: "3f80f-1b6-3e1cb03b"
    [5] => accept-ranges: bytes
    [6] => content-length: 438
    [7] => connection: close
    [8] => content-type: text/html
)

array
(
    [0] => http/1.1 200 ok
    [date] => sat, 29 may 2004 12:28:14 gmt
    [server] => apache/1.3.27 (unix)  (red-hat/linux)
    [last-modified] => wed, 08 jan 2003 23:11:55 gmt
    [etag] => "3f80f-1b6-3e1cb03b"
    [accept-ranges] => bytes
    [content-length] => 438
    [connection] => close
    [content-type] => text/html
)

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网