fishfin Posted July 29, 2008 Share Posted July 29, 2008 OK, I want to read some lines from a .txt file. I know that fgets() gets the line that the file pointer is on but I don't know how to move the pointer? What would be the easiest way to move the pointer down a line? Link to comment https://forums.phpfreaks.com/topic/117102-how-do-you-move-the-file-pointer/ Share on other sites More sharing options...
ronnie88 Posted July 29, 2008 Share Posted July 29, 2008 something like this, you can try it idk if it works just typed it <?php function readLine( $desiredLine, $handle, $length=1024 ) { if ( !$handle ) echo 'not a valid handle.'; $ctr = 0; while ( $ctr!=$desiredLine ) { $line = fgets( $handle, $length ); if ( feof($handle) ) { $line = 'error: invalid line number'; break; } $ctr++; } echo $line; } ?> Link to comment https://forums.phpfreaks.com/topic/117102-how-do-you-move-the-file-pointer/#findComment-602326 Share on other sites More sharing options...
Third_Degree Posted July 29, 2008 Share Posted July 29, 2008 http://php.net/fseek http://php.net/rewind Link to comment https://forums.phpfreaks.com/topic/117102-how-do-you-move-the-file-pointer/#findComment-602329 Share on other sites More sharing options...
fishfin Posted July 29, 2008 Author Share Posted July 29, 2008 So there is no easy way just to move up and down a line? Link to comment https://forums.phpfreaks.com/topic/117102-how-do-you-move-the-file-pointer/#findComment-602341 Share on other sites More sharing options...
Third_Degree Posted July 29, 2008 Share Posted July 29, 2008 well if you open the file with the file() function, moving around an array is easy... Link to comment https://forums.phpfreaks.com/topic/117102-how-do-you-move-the-file-pointer/#findComment-602364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.