3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doc = new DOMDocument; $doc->loadHTML('<html><body id="x"><div id="y"></div></body></html>'); $body = $doc->getElementById('x'); $div = $doc->getElementById('y'); $body->removeChild($div); echo '1: ' . ( $doc->getElementById('y') ? $doc->saveHTML( $doc->getElementById('y') ) : 'null' ) .PHP_EOL; // <div id="y"> unset($div); echo '2: ' . ( $doc->getElementById('y') ? $doc->saveHTML( $doc->getElementById('y') ) : 'null' ) .PHP_EOL; // null
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.10, 8.0.0alpha1 - beta3
1: <div id="y"></div> 2: null