イムでほんの数例では、いくつかのHTMLタグを削除し、私はこのから<p class="xxx"></p>
タグは、PHPを使用してPHP
を削除する方法を知りたい:これまで
<p class="xxx">
<a href="xxx" target="xxx">
<figure>
<img src="xxx"/>
<figcaption class="xxx">
<h1 class="xxx">Text</h1>
<cite class="xxx">Text</cite>
</figcaption>
</figure>
</a>
</p>
:
<a href="xxx" target="xxx">
<figure>
<img src="xxx"/>
<figcaption class="xxx">
<h1 class="xxx">Text</h1>
<cite class="xxx">Text</cite>
</figcaption>
</figure>
</a>
私は<p></p>
を削除したいときは<p><a><figure><img/><figcaption><h1></h1><cite></cite></figcaption></figure></a></p>
私はこれを試してみる:
$html = preg_replace("'
(<p[^>]*>)([^<]*<a[^>]*>[^<]*<figure[^>]*>[^<]*<img[^>]*>[^<]*<figcaption[^>]*>[^<]*<h1[^>]*>[^<]*</h1[^>]*>[^<]*<cite[^>]*>[^<]*</cite[^>]*>[^<]*</figcaption>[^<]*[^<]*</figure>[^<]*[^<]*</a>[^<]*)(</p>)'sim", "$2", $valBody);
echo '<H1>Nuevo </H1><br>' . $html;
しかし、私はそれを得る、あなたが私を助けてくれますか?
regexesは使用しないでください。 [DOM](http://php.net/dom)を使用してください。あなたは、より多くの時間を欲求不満で叫んで、DOMを学ぶよりも正規表現を理解しようとしている髪を引き裂いて、あなたの声帯と髪型を元通りに保ちます。 –
義務:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#answer-1732454 –