3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $html = "<p>Hello World</p> <div class='sometestclass'> <img src='foo.png'/> <div>Bar</div> </div>"; $clean = removeDiv ($html,'sometestclass'); echo $clean; function removeDiv ($html,$removeClass){ $dom = new DOMDocument; $dom->loadHTML( $html ); $xpath = new DOMXPath( $dom ); $removeString = ".//div[@class='$removeClass']"; $pDivs = $xpath->query($removeString); foreach ( $pDivs as $div ) { $div->parentNode->removeChild( $div ); } $output = preg_replace( "/.*<body>(.*)<\/body>.*/s", "$1", $dom->saveHTML() ); return $output; }
Output for 5.0.0 - 7.1.0
<p>Hello World</p>
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/1Qdk8 on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/1Qdk8 on line 12