3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<!DOCTYPE html> <title>Valid HTML5 Document</title> <p>Paragraph 1</p> <script>console.log("</html>Console log text");</script> <p>Paragraph 2</p>'; // DOM/HTMLDocument (lexbor) $newDom = \DOM\HTMLDocument::createFromString($html); $paragraphs = $newDom->getElementsByTagName('p'); echo "\n"; echo "DOM\HTMLDocument parsing (lexbor)\n"; echo "---------------------------------\n"; echo "{$paragraphs->length} paragraph elements found.\n"; // 2 paragraphs found (correct) foreach ($paragraphs as $p) { echo " * " . trim($p->textContent) . "\n"; } echo "\n"; echo "DOM serialised:\n"; echo $newDom->saveHtml();
Output for 8.4.1 - 8.4.2
DOM\HTMLDocument parsing (lexbor) --------------------------------- 2 paragraph elements found. * Paragraph 1 * Paragraph 2 DOM serialised: <!DOCTYPE html><html><head><title>Valid HTML5 Document</title> </head><body><p>Paragraph 1</p> <script>console.log("</html>Console log text");</script> <p>Paragraph 2</p></body></html>
Output for 8.2.25 - 8.2.26, 8.3.5 - 8.3.15
Fatal error: Uncaught Error: Class "DOM\HTMLDocument" not found in /in/uSNCT:9 Stack trace: #0 {main} thrown in /in/uSNCT on line 9
Process exited with code 255.

preferences:
50.09 ms | 407 KiB | 5 Q