3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doc = new DOMDocument; $xpath = new DOMXPath($doc); $frag = $doc->createDocumentFragment(); $frag->appendXML(' <div id="article"> <p>Some text</p> <p>More text</p> <pre><code> echo $variable; </code></pre> </div> '); $text_nodes = $xpath->query('descendant::text()[not(ancestor::pre)]', $frag); foreach ($text_nodes as $text_node) { $text_node->data = strrev($text_node->data); } echo $doc->saveHTML($frag);

preferences:
63.94 ms | 402 KiB | 5 Q