1

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

Isky
  • 1,328
  • 2
  • 14
  • 33

1 Answers1

1

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)
scoolnico
  • 3,055
  • 14
  • 24