Skip to content

Documented the DomCrawler option to normalize white spaces #12392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,18 @@ Access the value of the first node of the current selection::
// avoid the exception passing an argument that text() returns when node does not exist
$message = $crawler->filterXPath('//body/p')->text('Default text content');

// pass TRUE as the second argument of text() to remove all extra white spaces, including
// the internal ones (e.g. " foo\n bar baz \n " is returned as "foo bar baz")
$crawler->filterXPath('//body/p')->text('Default text content', true);

.. versionadded:: 4.3

The default argument of ``text()`` was introduced in Symfony 4.3.

.. versionadded:: 4.4

The option to trim white spaces in ``text()`` was introduced in Symfony 4.4.

Access the attribute value of the first node of the current selection::

$class = $crawler->filterXPath('//body/p')->attr('class');
Expand Down
11 changes: 11 additions & 0 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,13 @@ The Crawler can extract information from the nodes::
// returns the node value for the first node
$crawler->text();

// returns the default text if the node does not exist
$crawler->text('Default text content');

// pass TRUE as the second argument of text() to remove all extra white spaces, including
// the internal ones (e.g. " foo\n bar baz \n " is returned as "foo bar baz")
$crawler->text(null, true);

// extracts an array of attributes for all nodes
// (_text returns the node value)
// returns an array for each element in crawler,
Expand All @@ -703,6 +710,10 @@ The Crawler can extract information from the nodes::
return $node->attr('href');
});

.. versionadded:: 4.4

The option to trim white spaces in ``text()`` was introduced in Symfony 4.4.

Links
~~~~~

Expand Down