Isky
Isky

Reputation: 1398

Symfony DomCrawler take all div element in html file

I want to take all element in html file.

$crawler = new Crawler($html);
for($i = 0; $i < $crawler->filter("div")->count(); $i++){
     $div = $crawler->filter("div")->html();

Doing this I always take the first div element: How can I take all div element and add in an array? Thanks

Upvotes: 1

Views: 1227

Answers (1)

scoolnico
scoolnico

Reputation: 3135

Here is an easy way to achieve your goal:

$crawler = new Crawler($html);

$div = $crawler->filter('div')->each(function($node) {
    return $node->html();
});

// Array of result = $div 
// Number of result = sizeof($div)

Upvotes: 1

Related Questions