Skip to content

Commit

Permalink
minor #3527 Changes to components domcrawler (ifdattic)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

Changes to components domcrawler

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.3
| Fixed tickets |

Commits
-------

0576f70 Fix typos, minimize horizontal scrolling
  • Loading branch information
weaverryan committed Feb 4, 2014
2 parents 8973c81 + 0576f70 commit 9ba4fa7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions components/dom_crawler.rst
Original file line number Original file line 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:: .. note::


The DomCrawler will attempt to automatically fix your HTML to match the The DomCrawler will attempt to automatically fix your HTML to match the
official specification. For example, if you nest a `` <p>`` tag inside 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. 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 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 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>`. by :ref:`dumping it <component-dom-crawler-dumping>`.


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


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


To remove a node the anonymous function must return false. To remove a node the anonymous function must return false.


Expand Down

0 comments on commit 9ba4fa7

Please sign in to comment.