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

curl-and-php

Separate header from content

From: Kenneth Andresen <kandresen_at_gmx.net>
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:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" -L
"http://testsite.int"';

ob_start();
passthru($this->curl_command, $this->result_error);
$text = ob_get_contents();
ob_end_clean();
$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,
Kenneth
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-07-19