繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM