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); $preformattedCodeNode = $dom->createElement('pre'); foreach ($xpath->query("//code") as $codeNode) { $codeContent = ''; foreach($codeNode->childNodes as $codeChild) { $codeContent .= $dom->saveHTML($codeChild); } $preformattedCodeNode->textContent = $codeContent; $preformattedCodeNode->setAttribute('style', $codeNode->getAttribute('style')); $codeNode->parentNode->replaceChild($preformattedCodeNode, $codeNode); } $texte = $dom->saveHTML(); echo $texte;
Output for 8.0.30, 8.1.22 - 8.1.28, 8.2.9 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<!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> <pre 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; </pre> <a href="">Link rendered</a> </p> </body></html>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 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> <pre 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; </pre> <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> <pre 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;</pre> <a href="">Link rendered</a> </p></body></html>

preferences:
187.58 ms | 403 KiB | 152 Q