Remove last line in a file PHP/Store all lines except the last one
Hello all! Is there a way to remove the last line in a text file? Or, alternatively, is there a way to read a text file until the penultimate line of the file?
That is, if you have a file like:
Code:
AAAA
BBBB
CCCC
DDDD
XXXXXXXX
read all lines except the last one? In the previous example I need to hold only AAAA, BBBB , CCCC and DDDD.
Thank you!
Re: Remove last line in a file PHP/Store all lines except the last one
Use PHP's file() method which will return an array of the lines. Read through using a for() loop and leave off the last iteration.