Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Last active December 19, 2015 18:19
Show Gist options
  • Save ryanburnette/5997701 to your computer and use it in GitHub Desktop.
Save ryanburnette/5997701 to your computer and use it in GitHub Desktop.
This PHP snippet returns a status code when given HTTP headers in an array where each object is a string of one line.
function parse_http_headers_for_status($headers) {
foreach ( $headers as $line ) {
preg_match('#HTTP/\d+\.\d+ (\d+)#', $line, $matches);
if ( $matches[1] ) {
$status_code = $matches[1];
}
}
return $status_code;
}
@ryanburnette
Copy link
Author

I need to test this more thoroughly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment