@@ -285,12 +285,15 @@ and :phpclass:`DOMNode` objects:
285
285
Expression Evaluation
286
286
~~~~~~~~~~~~~~~~~~~~~
287
287
288
- The ``evaluate() `` method evaluates the given XPath expression.
289
- The return value depends on if the expression operates on simple values
290
- (like HTML attributes), or a subset of the current document.
291
- If the expression evaluates to a scalar value, an array of results will be
292
- returned. If the expression evaluates to a DOM document, a new ``Crawler ``
293
- instance will be returned.
288
+ .. versionadded ::
289
+ The :method: `Symfony\\ Component\\ DomCrawler\\ Crawler::evaluate ` method was
290
+ introduced in Symfony 3.2.
291
+
292
+ The ``evaluate() `` method evaluates the given XPath expression. The return
293
+ value depends on the XPath expression. If the expression evaluates to a scalar
294
+ value (e.g. HTML attributes), an array of results will be returned. If the
295
+ expression evaluates to a DOM document, a new ``Crawler `` instance will be
296
+ returned.
294
297
295
298
This behavior is best illustrated with examples::
296
299
@@ -308,31 +311,35 @@ This behavior is best illustrated with examples::
308
311
$crawler->addHtmlContent($html);
309
312
310
313
$crawler->filterXPath('//span[contains(@id, "article-")]')->evaluate('substring-after(@id, "-")');
311
- // array:3 [
312
- // 0 => "100"
313
- // 1 => "101"
314
- // 2 => "102"
315
- // ]
314
+ /* array:3 [
315
+ 0 => "100"
316
+ 1 => "101"
317
+ 2 => "102"
318
+ ]
319
+ */
316
320
317
321
$crawler->evaluate('substring-after(//span[contains(@id, "article-")]/@id, "-")');
318
- // array:1 [
319
- // 0 => "100"
320
- // ]
322
+ /* array:1 [
323
+ 0 => "100"
324
+ ]
325
+ */
321
326
322
327
$crawler->filterXPath('//span[@class="article"]')->evaluate('count(@id)');
323
- // array:3 [
324
- // 0 => 1.0
325
- // 1 => 1.0
326
- // 2 => 1.0
327
- // ]
328
+ /* array:3 [
329
+ 0 => 1.0
330
+ 1 => 1.0
331
+ 2 => 1.0
332
+ ]
333
+ */
328
334
329
335
$crawler->evaluate('count(//span[@class="article"])');
330
- // array:1 [
331
- // 0 => 3.0
332
- // ]
336
+ /* array:1 [
337
+ 0 => 3.0
338
+ ]
339
+ */
333
340
334
341
$crawler->evaluate('//span[1]');
335
- // Symfony\Component\DomCrawler\Crawler { }
342
+ // A Symfony\Component\DomCrawler\Crawler instance
336
343
337
344
Links
338
345
~~~~~
0 commit comments