Hello
I'm making RSS reader and I'm using DOM.
Now I stuck, trying to reverse the order of the items in the DOMNodeList.
I can make it with 2 cycles - one to make it as array and one for rsort().
Is there any way to reverse the order in the DOMNodeList or must be done with "the array way"?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Why don't you do it on the client side using javascript? The code for a given node n would be:
There is no method for reversing a DOMNodeList.
But you can keep it as it is, and if you need it, walk through it from the end to the start.
Example:
Just point at the end of the NodeList using NodeList->length, then decrement the index and access NodeList->item(index)
An alternative to using a documentFragment (which can end up with an unwanted "default:" namespace prefix): clone the NodeList, transfer all the items to the clone, then replace the original node: