<?php
<?php
function parseHeaders($headers)
{
$headers = preg_split("/(\r|\n)+/", $headers, -1, PREG_SPLIT_NO_EMPTY);
$parse_headers = array();
for ($i = 1; $i < count($headers); $i++) {
list($key, $raw_value) = explode(':', $headers[$i], 2);
$key = trim($key);
$value = trim($raw_value);
if (array_key_exists($key, $parse_headers)) {
// See HTTP RFC Sec 4.2 Paragraph 5
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
// If a header appears more than once, it must also be able to
// be represented as a single header with a comma-separated
// list of values. We transform accordingly.
$parse_headers[$key] .= ',' . $value;
} else {
$parse_headers[$key] = $value;
}
}
return $parse_headers;
}
print_r(parseHeaders('HTTP/1.1 200 OK
x-amz-id-2: VY3SprXJgsllfuyxECb2ykYo74ZQO/V+cbGadSo/FFt1VysYO+f66gb18XM9h0LOnl4wei6XSdc=
x-amz-request-id: 00B4612940F92DAF
Date: Tue, 05 Jan 2016 20:50:25 GMT
ETag: "9d3213e68a63ed25415b44031ccf6a37"
Content-Length: 0
Server: AmazonS3'));