I have a txt file and I need to delete the last line, but it is blank.
I tried the code below and it erases only the top line of the last one that would be the one that is blank.
Follow the code below:
$lines = file('file.txt');
$last = sizeof($lines) - 1 ;
unset($lines[$last]);
$fp = fopen('file.txt', 'w');
fwrite($fp, implode('', $lines));
fclose($fp);