私は、テキストファイルとの間のすべてを削除する方法を理解しようとしています。
これまでのところ、ファイルからurlset全体を削除するこれがあります。
$myFile = "/here/it/is/sitemap.xml";
$stringdata = file_get_contents($myFile);
$stringdata = preg_replace('#(<urlset.*?>).*?(</urlset>)#', '$1$2', $stringdata);
$stringdata = str_replace('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"></urlset>', '', $stringdata);
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $stringdata);
fclose($fh);
return;
問題は、テキストファイルにいくつかのurlsetがありますが、特定の変数に一致するurlsetの1つだけを削除したいので、次のようになります(これは機能しません):
$stringdata = preg_replace('#(<urlset.*?>).*? . $thisvariableisintheurlset . (</urlset>)#', '$1$2', $stringdata);
ターゲットのURLセットを削除するためにこれに何を追加する必要があるか、またはこれが問題を攻撃するための悪い方法のように見える場合はさらに良い方法を誰かが知っていますか?
ありがとう