3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <html> <body> <div class="regular-box">DIV 0</div> <div class="comments-box">DIV 1</div> <div class="heycomments-box">DIV 2</div> <div class="sdfcomments-box">DIV 3</div> <div class="sdgsdgcomments-boxsdfdfh">DIV 4</div> </body> </html> HTML; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $xp = new DOMXPath($dom); // get the node list of div nodes with "target" class $spanNodeList = $xp->query('//div[contains(@class, "comments-box")]'); foreach ($spanNodeList as $spanNode) { $spanNode->parentNode->replaceChild($spanNode->firstChild, $spanNode); } echo $dom->saveHTML();
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<html> <body> <div class="regular-box">DIV 0</div> DIV 1 DIV 2 DIV 3 DIV 4 </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 <html> <body> <div class="regular-box">DIV 0</div> DIV 1 DIV 2 DIV 3 DIV 4 </body> </html>

preferences:
155.13 ms | 402 KiB | 181 Q