- print_r: documentation ( source)
- html_entity_decode: documentation ( source)
- libxml_use_internal_errors: documentation ( source)
<?php
$html = '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div id="div1"><div id="div2">222</div><div id="div3">333</div></div></body></html>';
$doc = new DOMDocument;
libxml_use_internal_errors(true);
$doc->loadHTML($html);
$div1=$doc->getElementById('div1');
$div2=$doc->getElementById('div2');
$div3=$doc->getElementById('div3');
print_r($div2);
print_r($div3);
$div1->nodeValue='';
$div1->appendChild($doc->createTextNode(html_entity_decode('111')));
print_r(array($div2,$div2->parentNode));
print_r(array($div3,$div3->parentNode));
$div3->parentNode->removeChild($div3);
echo $doc->saveHTML();