Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50c0823

Browse files
committed
minor #10898 Documented the default values of text() and html() (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Documented the default values of text() and html() Documents symfony/symfony#28581 See also https://symfony.com/blog/new-in-symfony-4-3-domcrawler-improvements Commits ------- 851956d Documented the default values of text() and html()
2 parents ef64a7e + 851956d commit 50c0823

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

components/dom_crawler.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,16 @@ Access the node name (HTML tag name) of the first node of the current selection
201201

202202
Access the value of the first node of the current selection::
203203

204+
// if the node does not exist, calling to text() will result in an exception
204205
$message = $crawler->filterXPath('//body/p')->text();
205206

207+
// avoid the exception passing an argument that text() returns when node does not exist
208+
$message = $crawler->filterXPath('//body/p')->text('Default text content');
209+
210+
.. versionadded:: 4.3
211+
212+
The default argument of ``text()`` was introduced in Symfony 4.3.
213+
206214
Access the attribute value of the first node of the current selection::
207215

208216
$class = $crawler->filterXPath('//body/p')->attr('class');
@@ -298,8 +306,16 @@ and :phpclass:`DOMNode` objects::
298306
Or you can get the HTML of the first node using
299307
:method:`Symfony\\Component\\DomCrawler\\Crawler::html`::
300308

309+
// if the node does not exist, calling to html() will result in an exception
301310
$html = $crawler->html();
302311

312+
// avoid the exception passing an argument that html() returns when node does not exist
313+
$html = $crawler->html('Default <strong>HTML</strong> content');
314+
315+
.. versionadded:: 4.3
316+
317+
The default argument of ``html()`` was introduced in Symfony 4.3.
318+
303319
Expression Evaluation
304320
~~~~~~~~~~~~~~~~~~~~~
305321

0 commit comments

Comments
 (0)