阅读(1368) (0)

parse_header()

2017-06-22 13:58:18 更新

作用:将原生的头部信息解析为关联数组。 语法: array parse_header(string $header_str) 参数:

  • $header_str 头部信息字符串。

返回值:

  • 解析结果。

示例:

<?php
$header = 'HTTP/1.1 200 OK
Date: Wed, 28 Sep 2016 04:46:33 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
X-Powered-By: PHP/5.4.16
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8';
print_r(parse_header($header));
/** 将输出如下
Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Wed, 28 Sep 2016 04:46:33 GMT
    [Server] => Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
    [X-Powered-By] => PHP/5.4.16
    [Expires] => Thu, 19 Nov 1981 08:52:00 GMT
    [Cache-Control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    [Pragma] => no-cache
    [Keep-Alive] => timeout=5, max=100
    [Connection] => Keep-Alive
    [Transfer-Encoding] => chunked
    [Content-Type] => text/html; charset=UTF-8
)
*/