8000 minor #12392 Documented the DomCrawler option to normalize white spac… · symfony/symfony-docs@c746a77 · GitHub
[go: up one dir, main page]

Skip to content

Commit c746a77

Browse files
committed
minor #12392 Documented the DomCrawler option to normalize white spaces (javiereguiluz)
This PR was merged into the 4.4 branch. Discussion ---------- Documented the DomCrawler option to normalize white spaces Fixes #12388. Commits ------- 9556e4c Documented the DomCrawler option to normalize white spaces
2 parents 8b053bc + 9556e4c commit c746a77

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

components/dom_crawler.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,18 @@ Access the value of the first node of the current selection::
232232
// avoid the exception passing an argument that text() returns when node does not exist
233233
$message = $crawler->filterXPath('//body/p')->text('Default text content');
234234

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

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

243+
.. versionadded:: 4.4
244+
245+
The option to trim white spaces in ``text()`` was introduced in Symfony 4.4.
246+
239247
Access the attribute value of the first node of the current selection::
240248

241249
$class = $crawler->filterXPath('//body/p')->attr('class');

testing.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,13 @@ The Crawler can extract information from the nodes::
692692
// returns the node value for the first node
693693
$crawler->text();
694694

695+
// returns the default text if the node does not exist
696+
$crawler->text('Default text content');
697+
698+
// pass TRUE as the second argument of text() to remove all extra white spaces, including
699+
// the internal ones (e.g. " foo\n bar baz \n " is returned as "foo bar baz")
700+
$crawler->text(null, true);
701+
695702
// extracts an array of attributes for all nodes
696703
// (_text returns the node value)
697704
// returns an array for each element in crawler,
@@ -703,6 +710,10 @@ The Crawler can extract information from the nodes::
703710
return $node->attr('href');
704711
});
705712

713+
.. versionadded:: 4.4
714+
715+
The option to trim white spaces in ``text()`` was introduced in Symfony 4.4.
716+
706717
Links
707718
~~~~~
708719

0 commit comments

Comments
 (0)
0