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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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.