I have the following code:
<?php
$li = ('www.somesite.com');
$ht = file_get_contents($li);
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($ht);
$divs = $dom->getElementsByTagName('section');
foreach ($divs as $div){
if(preg_match('/\btresc\b/', $div->getAttribute('id'))) {
$chapter = $div->getElementsByTagName('div1')->item(0);
$oldchapter = $div->removeChild($chapter);
echo $oldchapter;
}
}
?>
I'm trying to remove <div class="div1">.*</div>
with <section id="tresc">.*</section>
However, I get the following error: Fatal error: Call to a member function removeChild() on a non-object.
Does anybody know what I'm doing wrong here? Any help is greatly appreciated!