PHP: Read Specific Line From File

后端 未结 12 632
天命终不由人
天命终不由人 2020-11-28 08:15

I\'m trying to read a specific line from a text file using php. Here\'s the text file:

foo  
foo2

How would I get the content of the seco

12条回答
  •  抹茶落季
    2020-11-28 09:09

    You could try looping until the line you want, not the EOF, and resetting the variable to the line each time (not adding to it). In your case, the 2nd line is the EOF. (A for loop is probably more appropriate in my code below).

    This way the entire file is not in the memory; the drawback is it takes time to go through the file up to the point you want.

    
    

提交回复
热议问题