note 101893 deleted from function.http-parse-message by danbrown

From: Date: Mon, 17 Jan 2011 14:31:23 +0000
Subject: note 101893 deleted from function.http-parse-message by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175823@lists.php.net to get a copy of this message
Note Submitter: A.S. ---- A useful function, but I couldn't use it because it's not installed on my host. Here's an alternative I found at http://snipplr.com/view/17242/parse-http-response/ : function parse_http_response ($string) { $headers = array(); $content = ''; $str = strtok($string, "\n"); $h = null; while ($str !== false) { if ($h and trim($str) === '') { $h = false; continue; } if ($h !== false and false !== strpos($str, ':')) { $h = true; list($headername, $headervalue) = explode(':', trim($str), 2); $headername = strtolower($headername); $headervalue = ltrim($headervalue); if (isset($headers[$headername])) $headers[$headername] .= ',' . $headervalue; else $headers[$headername] = $headervalue; } if ($h === false) { $content .= $str."\n"; } $str = strtok("\n"); } return array($headers, trim($content)); }

« previous php.notes (#175823) next »