hey there,
I am trying to write a simple script that lets me remove lines from a file.
I have an elementet.txt file that contains one-word lines. I thought that if I put the file lines onto an array, and then put back the array elements back on file, excluding the one I select from a drop down list, I would effectively remove a line from my file. But that is not working.
<?php
if(isset($_POST['elem'])){//this executes if the element to be removed is selected
$lines = file("elementet.txt");//I read the file onto an array
$file = "elementet.txt";
$fh = fopen($file, 'w');//open the file for writing
foreach($lines as $num => $l){
//if the line being read is not the one selected, put it back on file
if($_POST['elem'] != $l){
fwrite($fh, $l);
echo $_POST['elem'];
}
}
fclose($fh);
}
?>
for some reason, my if($_POST != $l) statement is always returning true. what am I missing?
thank you!