File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff 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+
239247Access the attribute value of the first node of the current selection::
240248
241249 $class = $crawler->filterXPath('//body/p')->attr('class');
Original file line number Diff line number Diff 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+
706717Links
707718~~~~~
708719
You can’t perform that action at this time.
0 commit comments