Skip to content

Instantly share code, notes, and snippets.

@rxnlabs
Last active August 29, 2015 14:04
Show Gist options
  • Save rxnlabs/9e135bf6deb90eb7340a to your computer and use it in GitHub Desktop.
Save rxnlabs/9e135bf6deb90eb7340a to your computer and use it in GitHub Desktop.
PHP - get headers from cURL request
<?php
function get_headers_curl($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