3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->recover = true; $html = "<html><head><title>blah</title></head><body><h2>Hi!</h2><h1>Blah</h1><h2>Bye!</h2></body></html>"; $dom->loadHTML($html); $h2 = $dom->getElementsByTagName("h2"); var_dump($h2); foreach($h2 as $element) { echo $element->ownerDocument->saveHTML($element); }
Output for 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
object(DOMNodeList)#2 (1) { ["length"]=> int(2) } <h2>Hi!</h2><h2>Bye!</h2>
Output for 5.3.11 - 5.3.29, 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33
object(DOMNodeList)#2 (1) { ["length"]=> int(2) } <h2>Hi!</h2> <h2>Bye!</h2>
Output for 5.3.6 - 5.3.10, 5.4.0
object(DOMNodeList)#2 (0) { } <h2>Hi!</h2> <h2>Bye!</h2>
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.5
object(DOMNodeList)#2 (0) { } Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/odpW1 on line 12 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/odpW1 on line 12
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/odpW1 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/odpW1 on line 3

preferences:
86.1 ms | 2050 KiB | 4 Q