[英]PHP How to delete a specific line in a text file using user input?
A user selects a number "$Num = $_POST['Number']" from a drop down to delete a line from a text file. 用户从下拉菜单中选择一个数字“ $ Num = $ _POST ['Number']”,以从文本文件中删除一行。 Ex.
例如
Cat 猫
Dog 狗
Mouse 老鼠
Lets say they chose line 3. How do I delete the line in the file so it just prints: 假设他们选择了第3行。如何删除文件中的该行,使其仅打印:
Cat 猫
Dog 狗
using only the number they chose and not the actual words in the line? 仅使用他们选择的数字而不使用行中的实际单词?
Use this: 用这个:
$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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.