Hello,
I am new to php, and what I need to know and learn is a part of an assignment I normally wouldn't ask for help on the net for an assignment but my teacher is not very helpful and other students are struggling too! I have searched the net inside and out and have tried many things. My problem is that I am trying to remove a line from an array by clicking a delete button.
The outpur I need is:
a line of text that comes from my text file after it is exploded into an array | With a delete button here
next line of text that comes from my text file after it is exploded into an array | With a delete button here
etc
I have managed to write this much myself -
<?php
$file = fopen('fav/fav.txt', 'r');
$file = file_get_contents('fav/fav.txt');
$file_array = explode("\n",$file);
array_pop($file_array);
foreach($file_array as $line) {
echo "<form method='post' action=''>".$line.
"<input type='submit' name='post' value='delete'><br>";
$fh = fopen("fav/fav.txt",'w');
foreach ($file_array as $line) {
fwrite($fh,$line."\n");
}
fclose($fh);
}
?>
The array_pop deletes from the bottom instead of the line the button is next too, I realise I will need to use and if statement but this is the closest I have gotten.
Thanks in advance!!!