0
我有以下代碼:PHP DOM removeChild之不起作用
<?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;
}
}
?>
我試圖刪除<div class="div1">.*</div>
與<section id="tresc">.*</section>
不過,我得到以下錯誤:致命錯誤:調用一個成員函數removeChild之()在一個非對象上。 有人知道我在這裏做錯了嗎?任何幫助是極大的讚賞!