Eris Posted July 5, 2008 Share Posted July 5, 2008 i need to read only n-th line from a large file, n is given. what's the fastest way to do that? Link to comment https://forums.phpfreaks.com/topic/113384-solved-reading-from-file-just-a-little-help/ Share on other sites More sharing options...
Bauer418 Posted July 5, 2008 Share Posted July 5, 2008 Probably: $data = file('file.txt'); print $data[$n - 1]; file() creates an array with a new element for each line. I'd be curious to see if there's a better way. If you know the length of each line, you could combine fopen, fseek, and fread. Link to comment https://forums.phpfreaks.com/topic/113384-solved-reading-from-file-just-a-little-help/#findComment-582543 Share on other sites More sharing options...
Eris Posted July 5, 2008 Author Share Posted July 5, 2008 lines have different length and the file's very big. i was thinking about reaching the required line with fgets(), but maybe there's a better way? Link to comment https://forums.phpfreaks.com/topic/113384-solved-reading-from-file-just-a-little-help/#findComment-582546 Share on other sites More sharing options...
Eris Posted July 5, 2008 Author Share Posted July 5, 2008 Ok, i assume there is no better way. thanks anyway Bauer418 Link to comment https://forums.phpfreaks.com/topic/113384-solved-reading-from-file-just-a-little-help/#findComment-582565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.