Topic awaiting preservation: Removing Headers from a Server Response in PHP (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: |
posted 02-03-2006 17:23
Hi folks, |
Paranoid (IV) Inmate From: New Jersey, USA |
posted 02-04-2006 01:19
Try this code: function stripResponseHeader($source) { $headerend = strpos($source,"\r\n\r\n"); if (is_bool($headerend)) { $result = $source; } else { $result = substr($source,$headerend+4,strlen($source) - ($headerend+4)); } return $result; }
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 02-04-2006 10:58
All HTTP Servers *must* return headers and seperate them from the body by a double link break - just as butcher parses in his code. |
Nervous Wreck (II) Inmate From: |
posted 02-04-2006 11:14
I instead used: code: function stripHeader($source) { list($header,$content) = explode("\r\n\r\n",$source); return $content; }
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 02-04-2006 14:26
You're code will fail if there's any double line break in the body, and there's nothing in the spec that will prevent that. |
Nervous Wreck (II) Inmate From: |
posted 02-04-2006 19:40
Thanks, Tyberius. I only need this response from a particular website which does have a doctype, but you're right about looking for doctypes more generally. What about the code below? explode() allows a limit parameter, which should (a) keep from wasting processor cycles and (b) splitting additional line breaks? code: function stripHeader($source) { list($header,$content) = explode("\r\n\r\n",$source,2); return $content; }
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 02-06-2006 09:57
Still... Why would the limit be two and not one? |
Nervous Wreck (II) Inmate From: |
posted 02-06-2006 23:40
quote: -- PHP Manual |