私はファイルphpを持っています:
<?php
$content = "
<script>
include string show_ads_1 and other string 1
</script>
<script>
include string show_ads_2 and other string 2
</script>
<script>
include string show_ads_x and other string x
</script>
<script>
not include 'show _ ads _ x' --> keeping this
</script>
<script type=\"text/javascript\">
include string 'show_ads_x' but keeping this because <script type='text/javascript'> not <script>
</script>
";
//Only remove tag <script></script> if includes "show_ads" string
$content = preg_replace('/(<script>)(show_ads.*?)(<\/script>)/s', '$2', $content);
echo $content;
?>
<script>...</script>
インクルード文字列「show_ads_」の間にコンテンツがある場合、すべてのコンテンツが削除さ<script>
れ</script>
ますが、保持されます。
しかし、上記のスクリプトは機能していません。何も削除されていません。それを実行してソースコードを表示すると、次のようになります。
include string show_ads_1 and other string 1
include string show_ads_2 and other string 2
include string show_ads_x and other string x
<script>
not include 'show _ ads _ x' --> keeping this
</script>
<script type="text/javascript">
include string 'show_ads_x' but keeping this because <script type='text/javascript'> not <script>
</script>