簡體   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