note 123374 added to class.domnodelist
| From: | nathan at wazu dot fr | Date: | Wed, 28 Nov 2018 14:29:48 +0000 |
| Subject: | note 123374 added to class.domnodelist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209788@lists.php.net to get a copy of this message | ||
10 years later the bug is still there.
You cannot loop throught a DOMNodeList using foreach.
For a weird reason it'll skip some items (in my case, it skips one item of two).
So one of the solution is:
$spans = $dom->getElementsByTagName('span');
$count = $spans->length;
// Put all the nodes in an array
for ($i = 0; $i < $count; $i++) {
$span_array[] = $spans->item($i);
}
foreach ($span_array as $span) {
// Now you can loop throught the list
}
----
Server IP: 208.43.231.9
Probable Submitter: 194.3.50.66
----
Manual Page -- http://php.net/manual/en/class.domnodelist.php
Edit -- https://master.php.net/note/edit/123374
Del: integrated -- https://master.php.net/note/delete/123374/integrated
Del: useless -- https://master.php.net/note/delete/123374/useless
Del: bad code -- https://master.php.net/note/delete/123374/bad+code
Del: spam -- https://master.php.net/note/delete/123374/spam
Del: non-english -- https://master.php.net/note/delete/123374/non-english
Del: in docs -- https://master.php.net/note/delete/123374/in+docs
Del: other reasons-- https://master.php.net/note/delete/123374
Reject -- https://master.php.net/note/reject/123374
Search -- https://master.php.net/manage/user-notes.php