Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheHiddenHaku/615bdd7b1f2d854508e2 to your computer and use it in GitHub Desktop.
Save TheHiddenHaku/615bdd7b1f2d854508e2 to your computer and use it in GitHub Desktop.
Get Curl response headers as associative array
/**
* 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