note 83976 modified in function.get-headers by danbrown

From: Date: Mon, 09 Jan 2012 19:58:40 +0000
Subject: note 83976 modified in function.get-headers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185493@lists.php.net to get a copy of this message
Should be the same than the original get_headers(): <?php if (!function_exists('get_headers')) { function get_headers($url, $format=0) { $headers = array(); $url = parse_url($url); $host = isset($url['host']) ? $url['host'] : ''; $port = isset($url['port']) ? $url['port'] : 80; $path = (isset($url['path']) ? $url['path'] : '/') . (isset($url['query']) ? '?' . $url['query'] : ''); $fp = fsockopen($host, $port, $errno, $errstr, 3); if ($fp) { $hdr = "GET $path HTTP/1.1\r\n"; $hdr .= "Host: $host \r\n"; $hdr .= "Connection: Close\r\n\r\n"; fwrite($fp, $hdr); while (!feof($fp) && $line = trim(fgets($fp, 1024))) { if ($line == "\r\n") break; list($key, $val) = explode(': ', $line, 2); if ($format) if ($val) $headers[$key] = $val; else $headers[] = $key; else $headers[] = $line; } fclose($fp); return $headers; } return false; } } ?> --was-- Should be the same than the original get_headers(): if (!function_exists('get_headers')) { function get_headers($url, $format=0) { $headers = array(); $url = parse_url($url); $host = isset($url['host']) ? $url['host'] : ''; $port = isset($url['port']) ? $url['port'] : 80; $path = (isset($url['path']) ? $url['path'] : '/') . (isset($url['query']) ? '?' . $url['query'] : ''); $fp = fsockopen($host, $port, $errno, $errstr, 3); if ($fp) { $hdr = "GET $path HTTP/1.1\r\n"; $hdr .= "Host: $host \r\n"; $hdr .= "Connection: Close\r\n\r\n"; fwrite($fp, $hdr); while (!feof($fp) && $line = trim(fgets($fp, 1024))) { if ($line == "\r\n") break; list($key, $val) = explode(': ', $line, 2); if ($format) if ($val) $headers[$key] = $val; else $headers[] = $key; else $headers[] = $line; } fclose($fp); return $headers; } return false; } } http://php.net/manual/en/function.get-headers.php

« previous php.notes (#185493) next »