cUrl... read a line number?

software development

#1

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

#2

[quote]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.[/quote]
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 [color=#CC0000]SCJESSEY97[/color]


#3

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

  • mahuti