I've tried a lot of potential solutions, but none of them are working for me. The simplest one:
$file = file('list.html');
array_pop($file);
isn't doing anything at all. Am I doing something wrong here? Is it different because it's an html file?
The line break can be removed from string by using str_replace() function.
The unlink() function deletes a file.
This should works :
<?php
// load the data and delete the line from the array
$lines = file('filename.txt');
$last = sizeof($lines) - 1 ;
unset($lines[$last]);
// write the new data to the file
$fp = fopen('filename.txt', 'w');
fwrite($fp, implode('', $lines));
fclose($fp);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With