Code: Select all
<?php
function delxlines($txtfile, $numlines)
{
if (file_exists("temp.txt"))
{
unlink("temp.txt");
}
$arrayz = file("$txtfile");
$tempWrite = fopen("temp.txt", "w");
for ($i = $numlines; $i < count($arrayz); $i++)
{
fputs($tempWrite, "$arrayz[$i]");
}
fclose($tempWrite);
copy("temp.txt", "$txtfile");
unlink("temp.txt");
}
//delxlines("comments.txt", 3);
?>
<input type="submit" value="" onsubmit="<?php delxlines("comments.txt", 3);?>" />Code: Select all
$file = fopen("comments.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file);
echo "<input type=\"submit\" value=\"Delete\" onsubmit=\"<?php del_line_in_file('comments.txt', 'wait');?>\" /><br />";
echo "<br />";
}
fclose($file);