Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php dom removeChild error issue

Tags:

dom

php

xhtml

I am getting an error on trying to remove nodes within xhtml.
The code is:

foreach($post->getElementsByTagName('a') as $key=>$a)
{
    $post->removeChild($a);
}

Fatal error: Uncaught exception 'DOMException' with message 'Not Found Error' in /var/www/content.php(24): content->fetch() #2 {main} thrown in /var/www/content.php on line 192

If i use img tag instead, it removes all but one img nodes and no fatal errors.
What is going on here?

like image 584
sam Avatar asked Dec 03 '22 07:12

sam


1 Answers

try:

$a->parentNode->removeChild($a);
like image 131
Yoshi Avatar answered Dec 26 '22 10:12

Yoshi