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 8.0.30, 8.1.22 - 8.1.27, 8.2.9 - 8.2.17, 8.3.0 - 8.3.4
<!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 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.29, 8.1.0 - 8.1.21, 8.2.0 - 8.2.8
<!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>

preferences:
130.06 ms | 403 KiB | 152 Q