error in removing an element
Posted: Wed Mar 17, 2010 1:06 pm
i am comparing for text contents that are repeated in 2 web pages and removing the repeated contnt...after comparing for the similar elements , when i try to remove the repeated elements , i get an error as follows "Fatal error: Call to a member function removeChild() on a non-object in c:\wamp\www\b.php on line 38 "..i have shown the error line as bold in the code..how do i correct it
Code: Select all
$doc = new DOMDocument(); // An instance of DOMDocument
@$doc->loadHTMLFile('http://www.web-source.net/web_design_tips/');
$doc2 = new DOMDocument(); // An instance of DOMDocument
@$doc2->loadHTMLFile('http://www.web-source.net/html_codes_chart.htm');
$bold_text = array();
$bold_text2 = array();
$bold_elements = $doc->getElementsByTagName('b');
foreach($bold_elements as $element)
$bold_text[] = $element->textContent;
$bold_elements2 = $doc2->getElementsByTagName('b');
foreach($bold_elements2 as $element2)
$bold_text2[] = $element2->textContent;
$domElemsToRemove=array();
$srcBoth = array_intersect($bold_text , $bold_text2);
foreach ($srcBoth as $img)
{
$domElemsToRemove[] = $img;
}
foreach( $domElemsToRemove as $img )
{
[u][b]$img->removeChild($img)[/b];[/u]
}
echo $doc->saveHTML();