Skip to content

Commit e835991

Browse files
author
wasinger
committed
added note on changed behavior of text()
1 parent c7471de commit e835991

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Tests/HtmlPageCrawlerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ public function testClone()
535535

536536
public function testText()
537537
{
538+
// ATTENTION: Contrary to the parent Crawler class, which returns the text from the first element only,
539+
// this functions returns the combined text of all elements (as jQuery does)
540+
538541
$c = HtmlPageCrawler::create('<p>abc</p><p>def</p>');
539542
$this->assertEquals('abcdef', $c->text());
540543
$c->text('jklo');

src/HtmlPageCrawler.php

+7
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,13 @@ public function replaceWith($content)
665665
* Get the combined text contents of each element in the set of matched elements, including their descendants,
666666
* or set the text contents of the matched elements.
667667
*
668+
* ATTENTION: Contrary to the parent Crawler class, which returns the text from the first element only,
669+
* this functions returns the combined text of all elements (as jQuery does). If this is not what you need you
670+
* must call ->first() before calling ->text(), e.g.
671+
*
672+
* in Symfony\DOMCrawler\Crawler: $c->filter('p')->text() returns the text of the first paragraph only
673+
* in HtmlPageCrawler you need to call: $c->filter('p')->first()->text()
674+
*
668675
* @param null|string $text
669676
* @return string|HtmlPageCrawler
670677
* @api

0 commit comments

Comments
 (0)