複数行にテキストがあるテキストファイル(in.txt)があります。変数文字列を検索し、見つかった場合はその行全体を削除する必要がありますが、他の行は保持します。以下のスクリプトを使用しましたが、すべてのデータが削除され、検索したものが書き込まれているようです。誰かが私を正しい方向に向けることができますか?「key」は私が検索している文字列です。
$key = $_REQUEST['key'];
$fc=file("in.txt");
$f=fopen("in.txt","w");
foreach($fc as $line)
{
if (!strstr($line,$key))
fputs($f,$line);
}
fclose($f);