3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $html = " <html> <body> <div id='div1'></div> <div id='div2'> Some text <span>Inside a span</span> <div>Nested div</div> </div> <div id='div3'> Some text <span>Inside a span</span> <div>Nested div</div> </div> </body> </html>"; $doc = new DOMDocument(); $doc->loadHTML($html); $div = $doc->getElementById("div2"); $div2 = $doc->getElementById("div3"); echo $div->ownerDocument->saveHTML($div); echo $div2->ownerDocument->saveHTML($div);
based on 773je
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
<div id="div2"> Some text <span>Inside a span</span> <div>Nested div</div> </div><div id="div2"> Some text <span>Inside a span</span> <div>Nested div</div> </div>