How can I remove DOM element tags but leave their contents?
<p>I have PHP code which removes all nodes that have at least one attribute. <a href="https://3v4l.org/XLm6o" rel="nofollow">Here</a> is my code:</p>

<pre><code>&lt;?php

$data = &lt;&lt;&lt;DATA
&lt;div&gt;
    &lt;p&gt;These line shall stay&lt;/p&gt;
    &lt;p class="myclass"&gt;Remove this one&lt;/p&gt;
    &lt;p&gt;But keep this&lt;/p&gt;
    &lt;div style="color: red"&gt;and this&lt;/div&gt;
&lt;/div&gt;
DATA;

$dom = new DOMDOcument();
$dom-&gt;loadHTML($data, LIBXML_HTML_NOIMPLIED);
$dom-&gt;removeChild($dom-&gt;doctype);

$xpath = new DOMXPath($dom);

$lines_to_be_removed = $xpath-&gt;query("//*[count(@*)&gt;0]");

foreach ($lines_to_be_removed as $line) {
    $line-&gt;parentNode-&gt;removeChild($line);
}

// just to check
echo $dom-&gt;saveHTML();
?&gt;
</code></pre>

<p>As you see in the fiddle, this is the current output of code above:</p>

<pre><code>&lt;div&gt;
    &lt;p&gt;These line shall stay&lt;/p&gt;

    &lt;p&gt;But keep this&lt;/p&gt;

&lt;/div&gt;
</code></pre>

<p>While this is desired result:</p>

<pre><code>&lt;div&gt;
    &lt;p&gt;These line shall stay&lt;/p&gt;
    Remove this one
    &lt;p&gt;But keep this&lt;/p&gt;
    and this
&lt;/div&gt;
</code></pre>

<p>How can I do that?</p>