note 48445 added to function.get-headers

From: Date: Fri, 24 Dec 2004 01:20:18 +0000
Subject: note 48445 added to function.get-headers
Groups: php.notes 
Request: Send a blank email to php-notes+get-82224@lists.php.net to get a copy of this message
In response to dotpointer's modification of Jamaz' solution... Here is a small modification of your function, this adds the emulation of the optional $format parameter. <?php if(!function_exists('get_headers')) { /** * @return array * @param string $url * @param int $format * @desc Fetches all the headers * @author cpurruc fh-landshut de * @modified by dotpointer * @modified by aeontech */ function get_headers($url,$format=0) { $url_info=parse_url($url); $port = isset($url_info['port']) ? $url_info['port'] : 80; $fp=fsockopen($url_info['host'], $port, $errno, $errstr, 30); if($fp) { $head = "HEAD ".@$url_info['path']."?".@$url_info['query']." HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n"; fputs($fp, $head); while(!feof($fp)) { if($header=trim(fgets($fp, 1024))) { if($format == 1) { $key = array_shift(explode(':',$header)); // the first element is the http header type, such as HTTP 200 OK, // it doesn't have a separate name, so we have to check for it. if($key == $header) { $headers[] = $header; } else { $headers[$key]=substr($header,strlen($key)+2); } unset($key); } else { $headers[] = $header; } } } return $headers; } else { return false; } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.get-headers.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48445 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48445&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48445&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48445&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48445&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48445&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48445&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48445&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82224) next »