用户选择一个号码" $ Num = $ _POST [' Number']"从下拉列表中删除文本文件中的一行。 实施例
猫
狗
小鼠
让我们说他们选择了第3行。如何删除文件中的行以便打印:
猫
狗
只使用他们选择的数字而不是行中的实际单词?
答案 0 :(得分:2)
使用此:
$row_number = 0; // Number of the line we are deleting
$file_out = file("file.txt"); // Read the whole file into an array
//Delete the recorded line
unset($file_out[$row_number]);
//Recorded in a file
file_put_contents("file.txt", implode("", $file_out));