How to loop through all nodes of Dom.
I use latest Symfony Crawler.
Simple example:
<?php
function test()
{
$crawler = new Crawler($html);
$crawler
->filter('body > ul')
->each(function (Crawler $node, $i) {
loop($node);
});
}
function loop(Crawler $node)
{
static $counter;
if ($node->filter('ul')->count() > 0) {
loop($node);
}
$counter++;
echo PHP_EOL,'Node: ', $counter, PHP_EOL;
}
I get a message:
Fatal error: Maximum function nesting level of '100' reached, aborting! in /.../vendor/symfony/css-selector/XPath/Extension/NodeExtension.php on line 269
HTML for example:
<body>
<ul>
<li>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</li>
<li>baz</li>
</ul>
<ul>
<li>buz</li>
</ul>
<ul>
<li>uaz</li>
</ul>
</body>
Thanks
if($counter < 10), if I putif($counter < 90)fails again.loopwith the same node? Isn't it an infinite recursion?