Guest Posted February 25, 2007 Share Posted February 25, 2007 Can I use curl to select only a certian amount of a page instead of the whole thing. I just would like it to get the first couple of lines like 25 can i do this. I use this to get the whole page $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$url"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $html=curl_exec ($ch); curl_close ($ch); Quote Link to comment https://forums.phpfreaks.com/topic/40004-curl-not-whole-content/ Share on other sites More sharing options...
Orio Posted February 25, 2007 Share Posted February 25, 2007 Using curl, you can't. But if you can define what lines you want, maybe we can use the string functions to manipulate the result and return what we want. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/40004-curl-not-whole-content/#findComment-193560 Share on other sites More sharing options...
ShogunWarrior Posted February 25, 2007 Share Posted February 25, 2007 You could use the stream/file functions to read from it as a socket, and stop at 25 lines. So, something like: $f = fopen('http://site.com/page.php','r'); for( $i=0;$i<25,!feof($f);$i++ ) { //Do something with line $line = fgets($f); } Probably not working code, I don't know the f* functions well for remote pages. Quote Link to comment https://forums.phpfreaks.com/topic/40004-curl-not-whole-content/#findComment-193573 Share on other sites More sharing options...
Orio Posted February 25, 2007 Share Posted February 25, 2007 Yeah ShogunWarrior is right, you could use the file functions if you don't need to send post data and/or cookies (or any other stuff curl can do but the file functions can't). <?php $start_line = 10; //Set here the line to start from (first line is 0) $amount = 11; // The amount of lines you want to read $url = "http://www.TheDataYouNeed.com/file.txt"; //The file //This example fetches lines 10 to 20 $end_line = $start_line + $amount; $lines = file($url); $count = count($lines); $limit = ($count > $end_line) ? $end_line : $count; $result = ""; for($i = $start_line; $i <= $limit; $i++) $result .= $lines[$i]; echo $result; ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/40004-curl-not-whole-content/#findComment-193605 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.