Use code below to delete a line from a text file. If the deleted item is NOT the last element, it works fine. Deletes the line entirely.
$panel_dir = 'host.txt';
$panel_data = file($panel_dir);
$panel_out = array();
foreach($panel_data as $panel_line) {
if(trim($panel_line) != $panel_del) {
$panel_out[] = $panel_line;
}
}
$f_panel = fopen($panel_dir, "w+") or die("Error");
foreach($panel_out as $panel_line) {
fwrite($f_panel, $panel_line);
}
fclose($f_panel);
}
BUT if the deleted item is the LAST element, it will remove the line and then leave a blank line.
Open to better methods for deleting the entire line from text file.