Skip to content

Commit

Permalink
added note on changed behavior of text()
Browse files Browse the repository at this point in the history
  • Loading branch information
wasinger committed Jun 25, 2015
1 parent c7471de commit e835991
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tests/HtmlPageCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ public function testClone()

public function testText()
{
// ATTENTION: Contrary to the parent Crawler class, which returns the text from the first element only,
// this functions returns the combined text of all elements (as jQuery does)

$c = HtmlPageCrawler::create('<p>abc</p><p>def</p>');
$this->assertEquals('abcdef', $c->text());
$c->text('jklo');
Expand Down
7 changes: 7 additions & 0 deletions src/HtmlPageCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,13 @@ public function replaceWith($content)
* Get the combined text contents of each element in the set of matched elements, including their descendants,
* or set the text contents of the matched elements.
*
* ATTENTION: Contrary to the parent Crawler class, which returns the text from the first element only,
* this functions returns the combined text of all elements (as jQuery does). If this is not what you need you
* must call ->first() before calling ->text(), e.g.
*
* in Symfony\DOMCrawler\Crawler: $c->filter('p')->text() returns the text of the first paragraph only
* in HtmlPageCrawler you need to call: $c->filter('p')->first()->text()
*
* @param null|string $text
* @return string|HtmlPageCrawler
* @api
Expand Down

0 comments on commit e835991

Please sign in to comment.