note 109765 deleted from function.get-headers by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 15:54:00 +0000 |
| Subject: | note 109765 deleted from function.get-headers by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190347@lists.php.net to get a copy of this message | ||
Note Submitter: Chris
----
To expand on gabe at vtunnel dot com 's curl based solution
http://www.php.net/manual/en/function.get-headers.php#90434
You can use simple regex if you need the array keys named as if you were using get_headers() with
the format flag ex) get_headers(1)
function get_headers_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$r = curl_exec($ch);
$r = split("\n", $r);
$keys = array();
if(!empty($r)) $keys[] = array_shift($r);
foreach($r as $line){
preg_match('/.+:\s/',$line,$match);
if($match) $keys[substr($match[0],0,-2)] = preg_replace('/.+:\s/','',
$line);
}
return $keys;
}