@@ -221,16 +221,24 @@ Access the value of the first node of the current selection::
221
221
// avoid the exception passing an argument that text() returns when node does not exist
222
222
$message = $crawler->filterXPath('//body/p')->text('Default text content');
223
223
224
- // by default, text() trims white spaces , including the internal ones
224
+ // by default, text() trims whitespace characters , including the internal ones
225
225
// (e.g. " foo\n bar baz \n " is returned as "foo bar baz")
226
226
// pass FALSE as the second argument to return the original text unchanged
227
227
$crawler->filterXPath('//body/p')->text('Default text content', false);
228
228
229
- // innerText() is similar to text() but only returns the text that is
230
- // the direct descendant of the current node, excluding any child nodes
229
+ // innerText() is similar to text() but returns only text that is a direct
230
+ // descendant of the current node, excluding text from child nodes
231
231
$text = $crawler->filterXPath('//body/p')->innerText();
232
- // if content is <p>Foo <span>Bar</span></p>
233
- // innerText() returns 'Foo' and text() returns 'Foo Bar'
232
+ // if content is <p>Foo <span>Bar</span></p> or <p><span>Bar</span> Foo</p>
233
+ // innerText() returns 'Foo' and text() returns 'Foo Bar' respectively 'Bar Foo'
234
+
235
+ // if there are multiple text nodes, between other child nodes, like
236
+ // <p>Foo <span>Bar</span> Baz</p>
237
+ // innerText() returns only the first text node 'Foo'
238
+
239
+ // like text(), innerText() also trims whitespace characters by default,
240
+ // but you can get the unchanged text by passing FALSE as argument
241
+ $text = $crawler->filterXPath('//body/p')->innerText(false);
234
242
235
243
Access the attribute value of the first node of the current selection::
236
244
0 commit comments