PHP如何使用用户输入删除文本文件中的特定行?

时间:2017-05-08 23:31:11

标签: php html

用户选择一个号码" $ Num = $ _POST [' Number']"从下拉列表中删除文本文件中的一行。 实施例



小鼠

让我们说他们选择了第3行。如何删除文件中的行以便打印:


只使用他们选择的数字而不是行中的实际单词?

1 个答案:

答案 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));