简体   繁体   中英

Going backwards with Symfony DomCrawler

I'm using Symfony DomCrawler to parse my HTML. I'm reading articles on my website like this:

$domCrawler->filter('.post')->each(function (DomCrawler $post) {
    // ...
});

How can I walk through them backwards? I'd like to start from the post that is at the very bottom of the page and then go up.

Your can use count and eq functions. Do something like this.

for ($i = $nodes->count(); $i >= 0; $i--) {
     $node = $nodes->eq($i);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM