[英]PHP How to delete a specific line in a text file using user input?
用户从下拉菜单中选择一个数字“ $ 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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.