3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<EOD <h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"> <h4>Show this title in HTML</h4> <p>This paragraph must be in <strong>HTML</strong> and this <a href="">Link</a> too !</p> <?php echo "Display this PHP code!"; ?> <script> alert("Don't pop-up please!"); </script> </code> <a href="">Link rendered</a> </p> EOD; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); foreach ($xpath->query("//code") as $codeNode) { $codeContent = ''; while ($codeNode->hasChildNodes()) { $codeChild = $codeNode->firstChild; $codeContent .= $dom->saveHTML($codeChild); $codeNode->removeChild($codeChild); } $codeNode->textContent = $codeContent; } $texte = $dom->saveHTML(); echo $texte;
Output for 5.6.1 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.26, 8.1.0 - 8.1.13, 8.2rc1 - rc3
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"> &lt;h4&gt;Show this title in HTML&lt;/h4&gt; &lt;p&gt;This paragraph must be in &lt;strong&gt;HTML&lt;/strong&gt; and this &lt;a href=""&gt;Link&lt;/a&gt; too !&lt;/p&gt; &lt;?php echo "Display this PHP code!"; ?&gt;&lt;script&gt; alert("Don't pop-up please!"); &lt;/script&gt;</code> <a href="">Link rendered</a> </p></body></html>
Output for 5.3.6 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"></code> <a href="">Link rendered</a> </p></body></html>
Output for 5.3.3 - 5.3.5
Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"></code> <a href="">Link rendered</a> </p></body></html>
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.1, 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.2
Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 30 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"></code> <a href="">Link rendered</a> </p> </body></html>
Output for 5.1.2
Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/2hjIs on line 31 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"></code> <a href="">Link rendered</a> </p> </body></html>
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/2hjIs on line 21
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/2hjIs on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/2hjIs on line 21

preferences:
69.04 ms | 425 KiB | 12 Q