在少数情况下使用php删除一些html标签

im using php and i wanna know how to delete <p class="xxx"></p> tag

from this:

<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>

to this:

<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>

I wanna delete <p></p> just when <p><a><figure><img/><figcaption><h1></h1><cite></cite></figcaption></figure></a></p>

i try this:

$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;

but i cant get it, can you please help me.

If you want to do it with preg_replace(), here is how I did it:

<?php

$html =<<<HTML
<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>
HTML;

$pattern = '#(<p.+">)#';
$replace = '';
$html = preg_replace($pattern, $replace, $html);
$pattern = "#(</p>)#";
$replace = '';
$html = preg_replace($pattern, $replace, $html);
$pattern = "#(\s\s)+#";
$replace = '';
$html = preg_replace($pattern, $replace, $html);

echo '<H1>Nuevo </H1><br>' . $html;

?>

This code gives the output as like as it was asked:

<H1>Nuevo </H1><br><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>

I'm a newbie programmer and this is my first answer on Stack Overflow. Best regards.