Jump to content

[SOLVED] Read specific line from a text file


PC Nerd

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.