I have the following file:
<p>
<a href="a1">A1</a>
<a href="a2">A2</a>
<a id="a3">A3</a>
<a href="a4">A4</a>
</p>
I need to skip the a tags from within the list obtained by $para->look_down("tag"=>'a');, which have an id attribute equal to some value.
I am doing:
$str = '';
$str = $anchor->attr('id');
if ($str != 'a3') {
last;
}
This does not work when id attribute is not defined: it breaks out of the loop. How to do this?
What do you mean it doesn’t work? Do you get an error or a warning?
If I’m understanding correctly, you might want to do:
Note, the use of
nefor “not equal” instead of the numeric!=.Also, if you want to continue the loop instead of jumping out, you can “skip” by using
next;instead oflast;.