--TEST-- GH-11289 (DOMException: Not Found Error introduced in 8.2.6, 8.1.19) --EXTENSIONS-- dom --FILE--
HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $divs = iterator_to_array($dom->getElementsByTagName('div')->getIterator()); foreach ($divs as $div) { $fragment = $dom->createDocumentFragment(); $fragment->appendXML('

Hi!

'); $div->replaceWith(...$fragment->childNodes); } var_dump(str_replace("\n", "", $dom->saveHTML())); ?> --EXPECT-- string(55) "

Hi!

"