我用 Symfony 的 Crawler 解析我的 xml,但无法得到如何传递(换句话说继续)一个元素而不将其包含到最终数组中?
例如:
$node->filterXPath('//ExampleNode')->each(function(Crawler $child, $i) {
if (! count($child->filterXPath('//ChildNode'))) {
continue;
}
return $child->filterXPath('//ChildNode')->text();
});
最佳答案
您可以使用Symfony\Component\DomCrawler\Crawler::reduce(Closure)
$crawler->reduce(function($result, $item) {
$childNodes = $item->filterXPath('//ChildNode');
if ($childNodes->count()) {
$result[] = $item;
}
});
关于symfony - 如何在Crawler每个函数中传递一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36225365/