note 103848 deleted from function.http-parse-headers by danbrown
| From: | danbrown@php.net | Date: | Fri, 06 May 2011 14:51:07 +0000 |
| Subject: | note 103848 deleted from function.http-parse-headers by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179496@lists.php.net to get a copy of this message | ||
Note Submitter: coder at code dot nl
----
This one works better for me, the one below gave some preg_match resolve errors, the use of nl2br()
makes it work xplatform
<?php
function http_parse_headers($data)
{
$header_arr = array();
foreach (explode('<br />', nl2br($data, TRUE)) as $possible_header) {
// trim
$possible_header = trim($possible_header);
// stop parsing at first empty line
if (!$possible_header) break;
// look for value separator ':'
if (preg_match('/([^:]+): (.+)/m', $possible_header, $matches)) {
if (count($matches) == 3) {
$header_arr[$matches[1]] = $matches[2];
}
}
}
return $header_arr;
}
?>