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::
232
232
// avoid the exception passing an argument that text() returns when node does not exist
233
233
$message = $crawler->filterXPath('//body/p')->text('Default text content');
234
234
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
+
235
239
.. versionadded :: 4.3
236
240
237
241
The default argument of ``text() `` was introduced in Symfony 4.3.
238
242
243
+ .. versionadded :: 4.4
244
+
245
+ The option to trim white spaces in ``text() `` was introduced in Symfony 4.4.
246
+
239
247
Access the attribute value of the first node of the current selection::
240
248
241
249
$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::
692
692
// returns the node value for the first node
693
693
$crawler->text();
694
694
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
+
695
702
// extracts an array of attributes for all nodes
696
703
// (_text returns the node value)
697
704
// returns an array for each element in crawler,
@@ -703,6 +710,10 @@ The Crawler can extract information from the nodes::
703
710
return $node->attr('href');
704
711
});
705
712
713
+ .. versionadded :: 4.4
714
+
715
+ The option to trim white spaces in ``text() `` was introduced in Symfony 4.4.
716
+
706
717
Links
707
718
~~~~~
708
719
You can’t perform that action at this time.
0 commit comments