【发布时间】:2023-03-19 19:22:01
【问题描述】:
用户从下拉列表中选择一个数字“$Num = $_POST['Number']”以从文本文件中删除一行。 例如。
猫
狗
鼠标
假设他们选择了第 3 行。如何删除文件中的行以便它只打印:
猫
狗
只使用他们选择的数字而不是行中的实际单词?
【问题讨论】:
-
把你写的给我们
用户从下拉列表中选择一个数字“$Num = $_POST['Number']”以从文本文件中删除一行。 例如。
猫
狗
鼠标
假设他们选择了第 3 行。如何删除文件中的行以便它只打印:
猫
狗
只使用他们选择的数字而不是行中的实际单词?
【问题讨论】:
使用这个:
$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));
【讨论】: