DreamHost Web Hosting
Discussion Forum


Forums
   >> Programming
*Threaded Mode

Subject cUrl... read a line number?  
Posted bymahuti (DH New User )
Posted on09/07/06 08:20 AM



Hey Gang, I have a script that uses fopen that I'm converting to cUrl so that it's compatible with dreamhost. The script looks for information on a specific line number

$line=fgets($file,222);

basically all the information on line 222 is returned with the fopen script. With cUrl, I don't seem to be able to use fgets... I can't figure out what command I need to use to read information out of a specific line number. Any suggestions, links, information I could use to get started with this? All help would be greatly appreciated.

- mahuti


Subject Re: cUrl... read a line number? new [re: mahuti]  
Posted byscjessey (DH Pooh-Bah)
Posted on09/07/06 02:29 PM



In reply to:

Hey Gang, I have a script that uses fopen that I'm converting to cUrl so that it's compatible with dreamhost. The script looks for information on a specific line number

$line=fgets($file,222);

basically all the information on line 222 is returned with the fopen script.


Use cURL to grab everything, and then use further scripting to access the line you want. The following example should work:

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://example.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$lines = array();
$lines = explode("\n", $file_contents);
echo $lines[222];
?>

If the line is HTML, you will need to wrap convert the HTML entities to see it displayed:

echo htmlspecialchars($lines[222]);

--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code SCJESSEY97

Subject Re: cUrl... read a line number? new [re: scjessey]  
Posted bymahuti (DH New User )
Posted on09/07/06 02:35 PM



Ah, yeah, that's it. Hey, thanks much!

- mahuti



*Threaded Mode
Jump to