File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,10 @@ This allows you to use jQuery-like selectors to traverse::
70
70
71
71
Anonymous function can be used to filter with more complex criteria::
72
72
73
- $crawler = $crawler->filter('body > p')->reduce(function ($node, $i) {
73
+ use Symfony\Component\DomCrawler\Crawler;
74
+ // ...
75
+
76
+ $crawler = $crawler->filter('body > p')->reduce(function (Crawler $node, $i) {
74
77
// filter even nodes
75
78
return ($i % 2) == 0;
76
79
});
@@ -137,10 +140,18 @@ Extract attribute and/or node values from the list of nodes::
137
140
138
141
Call an anonymous function on each node of the list::
139
142
140
- $nodeValues = $crawler->filter('p')->each(function ($node, $i) {
143
+ use Symfony\Component\DomCrawler\Crawler;
144
+ // ...
145
+
146
+ $nodeValues = $crawler->filter('p')->each(function (Crawler $node, $i) {
141
147
return $node->text();
142
148
});
143
149
150
+ .. versionadded ::
151
+ As seen here, in Symfony 2.3, the ``each `` and ``reduce `` Closure functions
152
+ are passed a ``Crawler `` as the first argument. Previously, that argument
153
+ was a :phpclass: `DOMNode `.
154
+
144
155
The anonymous function receives the position and the node (as a Crawler) as arguments.
145
156
The result is an array of values returned by the anonymous function calls.
146
157
You can’t perform that action at this time.
0 commit comments