cURL / Mailing Lists / curl-and-php / Single Mail


Separate header from content

From: Kenneth Andresen <>
Date: Tue, 18 Jul 2006 22:02:14 -0500

Hello all,

I am trying to extract all the headers, the content, and the error codes
from the pages I visit using the following commands:

$this->command='curl -compressed -i -A "Mozilla/5.0 (X11; U; Linux i686;
en-US; rv: Gecko/20060508 Firefox/" -L

passthru($this->curl_command, $this->result_error);
$text = ob_get_contents();
$pattern = '/(.*)\x0d\x0a(.*)/s';
preg_match($pattern, $text, $matches);
$this->result_headers = $matches[1];
$this->result_content = $matches[2];

The reason for why I have tried to do it this way is that it seems much
easier to get ALL the headers such as whether the content was
compressed, using this method rather than the curl method, however I am
noticing that I am noticing that there are some problems separating the
header and the content again when there are more than one header such as
during a page redirect.

I would like to know if there are any easier ways to do this from the
PHP curl class, or if I need to rather create a more complicated regular
expression for example checking for whether the empty line is followed
by one starting with HTTP or not.

Best regards,
Received on 2006-07-19