I’m working with PHP here.
I want to extract the text below a specific line number. The reason why I want I want to do this is to remove HTTP Header information from a CURL response.
Below is some code from sample response data:
HTTP/1.1 203 OK
Date: Tue, 23 Aug 2011 20:56:41 GMT
Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.5
Set-Cookie: PHPSESSID=ke0uv5bm0mqjn3i3jad6n20co4; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Test-Header: This is my test header
Content-Length: 24
Content-Type: text/html
This is the get response
What I’d like to do is remove all the header information and return only my content i.e. “This is my get response”.
I’ve done this successfully with regular expressions, but I want to do something that simple clears the content above the main response, rather than match header content then replace with empty space.
Any ideas?
Thanks.
I did a little poking around and here’s what I came up with as a solution.
To get the number of line numbers taken up by my header content I wrote the following code:
And then to get content only, the following code will do that:
Where
$curl_response_resis the response data as mentioned in my question above.I’m not sure how efficient this code is, but for simple and relatively short response data from CURL it looks like it’ll do ok.
Thanks for the responses.