Created
May 11, 2015 13:30
-
-
Save TheHiddenHaku/615bdd7b1f2d854508e2 to your computer and use it in GitHub Desktop.
Get Curl response headers as associative array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Questo metodo prende l'header di una response e restituisce un array associativo | |
* @param $response | |
* @return array | |
*/ | |
private function get_headers_from_curl_response($response) | |
{ | |
$headers = array(); | |
$header_text = substr($response, 0, strpos($response, "\r\n\r\n")); | |
foreach (explode("\r\n", $header_text) as $i => $line) { | |
if ($i === 0) { | |
$headers['http_code'] = $line; | |
} else { | |
list ($key, $value) = explode(': ', $line); | |
$headers[$key] = $value; | |
} | |
} | |
return $headers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment