Just continue
on target
attributes which aren't fruit
, and then add the textContent
of the elements to an array.
$nodes = array();
for ($i; $i < $a->length; $i++) {
$attr = $a->item($i)->getAttribute('target');
if ($attr != 'fruit') {
continue;
}
$nodes[] = $a->item($i)->textContent;
}
$nodes
now contains all the nodes of the elements which have their target
attribute set to fruit
.