note 123374 rejected from class.domnodelist by cmb
| From: | cmb@php.net | Date: | Wed, 28 Nov 2018 14:49:49 +0000 |
| Subject: | note 123374 rejected from class.domnodelist by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209791@lists.php.net to get a copy of this message | ||
Note Submitter: nathan at wazu dot fr
----
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
}