Forum Moderators: coopster

Message Too Old, No Replies

cURL problem

         

Norky

9:35 pm on Mar 27, 2005 (gmt 0)

10+ Year Member



I'm writing an RSS reader in PHP, that will read remote feeds.

To do this I am using fread() to get the data, but I also need to get the size of the feed, so I'm using a cURL function:


ob_start();
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if (!empty($user) &&!empty($pw))
{
$headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$okay = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
if (isset($matches[1]))
{
$size = $matches[1];
}
else
{
$size = 0;
}

return $size;

This all works dandy, except for feeds generated by PHP/ASP where the content type is sent using a header(); and the XML is generated from a database or whathaveyou.

What can I do to make it see the final outputted data? I thought CURLOPT_HEADER would do this. Or is there an altogether simpler way of obtaining remote data?

coopster

10:06 pm on Mar 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Norky.

When you say size of the feed, do you mean the length of the contents? If so, why not just use file_get_contents() [php.net] and strlen() [php.net]?