generate functionSun, 20 Nov 2022

php domdocument unwrap first div

function unwrap_first_div($html) { $doc = new DOMDocument(); $doc->loadHtml($html); $xpath = new DOMXPath($doc); $divs = $xpath->query('//div'); if ($divs->length > 1) { $divs->item(0)->parentNode->replaceChild($doc->importNode($divs->item(0)->firstChild,TRUE), $divs->item(0)); } return $doc->saveHTML(); }

Questions about programming?Chat with your personal AI assistant