note 101786 added to function.get-headers

From: Date: Tue, 11 Jan 2011 11:36:50 +0000
Subject: note 101786 added to function.get-headers
Groups: php.notes 
Request: Send a blank email to php-notes+get-175627@lists.php.net to get a copy of this message
Unfortunately there is still no useful output format to handle redirects. This function will bring all non-broken headers into a usable format. Too bad it has to call the get_headers() funtion 2 times, but i dont see any other possibility right now. function page_get_headers($crawl_uri) { // get the array values where to split the second get headers return $headers = get_headers($crawl_uri, 1); if (empty($headers)) { return array(); } $splitmarks = array(); foreach ($headers as $key=>$h) { if (is_numeric($key)) { array_push($splitmarks, $h); } } // get the "real" headers $headers_final = array(); $i = 0; $headers = get_headers($crawl_uri); foreach ($headers as $head) { // if the value is one of the splitmarks, start the next header if ($head === $splitmarks[$i]) { $i++; } else { // get the headers name $tmp = explode(": ", $head, 2); // check if the header is already existing, if yes, parse the similar header to an array if (!empty($headers_final[$i-1][$tmp[0]])) { if (is_array($headers_final[$i-1][$tmp[0]])) { array_push($headers_final[$i-1][$tmp[0]], $tmp[1]); } else { $headers_final[$i-1][$tmp[0]] = array($headers_final[$i-1][$tmp[0]], $tmp[1]); } } else { $headers_final[$i-1][$tmp[0]] = $tmp[1]; } } } return $headers_final; } ---- Server IP: 217.160.235.204 Probable Submitter: 83.135.79.97 ---- Manual Page -- http://www.php.net/manual/en/function.get-headers.php Edit -- https://master.php.net/note/edit/101786 Del: integrated -- https://master.php.net/note/delete/101786/integrated Del: useless -- https://master.php.net/note/delete/101786/useless Del: bad code -- https://master.php.net/note/delete/101786/bad+code Del: spam -- https://master.php.net/note/delete/101786/spam Del: non-english -- https://master.php.net/note/delete/101786/non-english Del: in docs -- https://master.php.net/note/delete/101786/in+docs Del: other reasons-- https://master.php.net/note/delete/101786 Reject -- https://master.php.net/note/reject/101786 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175627) next »