I have a flat file database, and I'm wondering if I could enter a line, say, on a regular form, and have a PHP script find and delete that line in the flat file? Anyone know if this is possible? Thanks, Peter
function delete_line($line, $file) { if (!$lines = @file($file)) { trigger_error("File <i>{$file}</i> does not exists or can't be opened"); return false; } unset($lines[$line]); $fp = fopen($file, 'w'); fwrite($fp, implode("\n", array_map('trim', $lines))); fclose($fp); return true; } PHP: Usage: if (delete_line(5, 'test.txt')) { echo 'Line deleted'; } else { echo 'Line not deleted'; } ?> PHP: Note that the first line starts with 0, and not 1.
I've set it up with a form, and added some simple validation. Also added redirects for successful or unsuccessful attempts. Thanks again!