I am trying to delete p
tags with data-spotid
attribute
$dom = new DOMDocument();
@$dom->loadHTML($description);
$pTag = $dom->getElementsByTagName('p');
foreach ($pTag as $value) {
/** @var DOMElement $value */
$id = $value->getAttribute('data-spotid');
if ($id) {
$value->parentNode->removeChild($value);
}
}
but when i am removing child it is reindexing the dom. let suppose i have 8 items i deleted 1st it will reindex it and 2nd element will become 1st and it will not delete it will go to 2nd which is now 3rd element.
See Question&Answers more detail:os