Last active
December 19, 2015 18:19
-
-
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.
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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need to test this more thoroughly.