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

Skip to content

Changes to components domcrawler #3527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ interacting with html links and forms as you traverse through the HTML tree.
.. note::

The DomCrawler will attempt to automatically fix your HTML to match the
official specification. For example, if you nest a `` <p>`` tag inside
another `` <p>`` tag, it will be moved to be a sibling of the parent tag.
official specification. For example, if you nest a ``<p>`` tag inside
another ``<p>`` tag, it will be moved to be a sibling of the parent tag.
This is expected and is part of the HTML5 spec. But if you're getting
unexpected behavior, this could be a cause. And while the DomCrawler
isn't meant to dump content, you can see the "fixed" version if your HTML
isn't meant to dump content, you can see the "fixed" version of your HTML
by :ref:`dumping it <component-dom-crawler-dumping>`.

Node Filtering
Expand All @@ -83,10 +83,12 @@ Anonymous function can be used to filter with more complex criteria::
use Symfony\Component\DomCrawler\Crawler;
// ...

$crawler = $crawler->filter('body > p')->reduce(function (Crawler $node, $i) {
// filter even nodes
return ($i % 2) == 0;
});
$crawler = $crawler
->filter('body > p')
->reduce(function (Crawler $node, $i) {
// filter even nodes
return ($i % 2) == 0;
});

To remove a node the anonymous function must return false.

Expand Down