Created
June 15, 2010 17:01
-
-
Save streamsend/439378 to your computer and use it in GitHub Desktop.
How to parse headers from a CURL response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| class CurlResponse | |
| { | |
| var $headers = array(); | |
| function CurlResponse () {} | |
| function parse_header ($handle, $header) | |
| { | |
| $details = split(':', $header, 2); | |
| if (count($details) == 2) | |
| { | |
| $key = trim($details[0]); | |
| $value = trim($details[1]); | |
| $this->headers[$key] = $value; | |
| } | |
| return strlen($header); | |
| } | |
| } | |
| $response = new CurlResponse(); | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, "http://www.example.com"); | |
| curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$response, 'parse_header')); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_exec($ch); | |
| print_r($response->headers); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is not returning the location header correctly