PC Nerd Posted December 27, 2008 Share Posted December 27, 2008 Hi all, I'm looking to see if there is a better method than reading the entire file and then splitting it into an array ( at "\n"). I have a long text file, and I want to be able to select specific lines in the file. Eventually I anticipate that the file could be into the tens or hundreds of thousands of lines long so I would like to try not to have to load the entire file everytime the script runs. Thanks,PC_Nerd Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 27, 2008 Share Posted December 27, 2008 file reads the file line by line into an array straight away. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 27, 2008 Author Share Posted December 27, 2008 Ok thanks, but is there any specific way to read a specific line withought havbing to load the entire file ? Thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 27, 2008 Share Posted December 27, 2008 Not really. You can set a loop reading the file in line by line but this is long-winded and not the best option. If each line is always the same length then you can calculate the start position but this will be doomed to fail if one line is different in length to the others. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 27, 2008 Author Share Posted December 27, 2008 Ok thanks, Ive worked at the moment using file(); After reading in more depth about file(), I learned that the faster method it to manually read it from teh file using fread and then explode() based on a newline etc. I think there is a solution in teh comments for file(). Thanks! 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.