如何删除文本文件中的特定数据 (PHP)

How can I delete spesific data in a txt file (PHP)

我想从 txt 文件中删除特定数据。我的示例 txt 文件如下。我想在 <!--something--><!--#something--> 之间删除。 (包括这些 html 代码)。我如何在 PHP 中执行此操作?

我的示例 txt 文件:

etc. etc. etc.
<!--something-->
here is data what I want to delete.
<!--#something-->
etc. etc. et.

你可以使用这样的东西

$handle = fopen("inputfile.txt", "r");
$newFile = '';
$skipp = false;
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        if( stristr($line,'<!--something-->') !== false ) {
            $skipp = true;
        }
        if(!$skipp){
            $newFile .= $line;
        }
        if( stristr($line,'<!--#something-->') !== false ) {
            $skipp = false;
        }

    }

    fclose($handle);
}
//file_put_contents("inputfile.txt",$newFile)
echo $newFile;