note 101387 modified in domnode.removechild by danbrown
| From: | danbrown@php.net | Date: | Tue, 14 Dec 2010 15:25:26 +0000 |
| Subject: | note 101387 modified in domnode.removechild by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174905@lists.php.net to get a copy of this message | ||
For the loop bug, you have to use the parent node of the node itself :
<?php
$nodeList = $doc->getElementsByTagName('p');
for ($i = 0; $i < $nodeList->length; $i++) {
try {
$old_child = $nodeList->item($i)->parentNode->removeChild($nodeList->item($i));
} catch (DOMException $e) {
echo $e->getMessage();
}
}
?>
--was--
For the loop bug, you have to use the parent node of the node itself :
$nodeList = $doc->getElementsByTagName('p');
for ($i = 0; $i < $nodeList->length; $i++) {
try {
$old_child = $nodeList->item($i)->parentNode->removeChild($nodeList->item($i));
} catch (DOMException $e) {
echo $e->getMessage();
}
}
http://php.net/manual/en/domnode.removechild.php