3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doc = new DOMDocument; $xpath = new DOMXPath($doc); $frag = $doc->createDocumentFragment(); $frag->appendXML(<<<'HTML' <div id="article"> <p>Some text</p> <p>More text</p> <pre><code> echo $variable; </code></pre> </div> HTML ); $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->firstChild);

preferences:
25.81 ms | 404 KiB | 5 Q