generate functionSun, 20 Nov 2022

php domdocument unwrap first div

<?php $html = '<div> <div class="header"> <div class="header-child"> <h1>This is a heading</h1> </div> </div> </div>'; $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $divs = $xpath->query('//div'); $divs->item(0)->parentNode->removeChild($divs->item(0)); echo $dom->saveHTML();

Questions about programming?Chat with your personal AI assistant