php-readability
php-readability copied to clipboard
Iterate node lists with foreach
DOMNodeList
implements Traversable
.
There are some for
loops left but we cannot simply replace those: PHP follows the DOM specification, which requires that NodeList
objects in the DOM are live. As a result, any operation that removes a node list member node from its parent (such as removeChild
, replaceChild
or appendChild
) will cause the next node in the iterator to be skipped.
We could work around that by converting those node lists to static arrays using iterator_to_array
but not sure if it is worth it.
Also add few cleanups I noticed.
I have rebased this, deciding to skip the reverse for loops for now – the naïve port to iterator_to_array
does not really work (see #91, possibly due to nested nodes being matched by xpath) . Maybe it would work with array_reverse
but I will need too give the invariants deeper thought.