note 117291 deleted from function.get-headers by cmb
| From: | cmb@php.net | Date: | Mon, 18 May 2015 11:30:03 +0000 |
| Subject: | note 117291 deleted from function.get-headers by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-202589@lists.php.net to get a copy of this message | ||
Note Submitter: bobray at softville dot com
----
Correction to my earlier note on getting the last code returned as an int: if getHeaders() fails,
PHP will throw an error. Here's the corrected function:
function getStatus($url) {
$headers = @get_headers($url, true);
$value = NULL;
if ($headers === false) {
return $headers;
}
foreach ($headers as $k => $v) {
if (!is_int($k)) {
continue;
}
$value = $v;
}
return (int) substr($value, strpos($value, ' ', 8) + 1, 3);
}
Test the return value for === false.