ファイルを開いて行を読み取る必要があります。
<?php
if($action == "removeUser")
{
$filename = "users.txt";
// Open your file
$handle = fopen($filename, "r");
$new_content='';
echo "Valid input: <br><br>";
// Loop through all the lines
while($line = fgets($handle))
{
//try to find the string 'user' - Case-insensitive
if(stristr($line,"user")===FALSE)
{
// To remove white spaces
$line=trim($line);
if($line!='') echo $line."<br>";
//if doesn't contain the string "user",
// add it to new input
$new_content.=$line."\n";
}
}
// closes the file
fclose($handle);
$new_content=trim($new_content); // Remove the \n from the last line
echo "<br>Updating file with new content...";
file_put_contents($filename,$new_content);
echo "Ok";
}
?>
私はPHPには新しく、これは多くの助けとなりました – Reloaded
空白を削除する方法はありますか? – Reloaded
はい、 $ line = trim($ line);を使用して空白と空白行を削除できます。 –