Symfony News

New in Symfony 4.3: Better HTML5 parser for DomCrawler

Titouan Galopin

Contributed by
Titouan Galopin
in #29306 and #30892.

The DomCrawler component eases DOM navigation for HTML and XML documents, making it very useful for functional tests and web scrapers. Internally, this component uses the PHP DOM extension (and methods such as loadHtml()) to parse HTML contents, including HTML5.

Sadly, HTML5 support in PHP DOM extension is far from perfect and it includes some inconsistencies. In contrast, the third-party HTML5-PHP library provides a standards-compliant HTML5 parser and writer written entirely in PHP. Moreover it's been battle-tested in projects such as Drupal and has more than 7 million downloads.

That's why in Symfony 4.3 we've decided to optionally integrate this library in DomCrawler. If you don't make any change in your app, the component will keep using the PHP DOM extension. However, if you install the HTML5-PHP library in your app as follows:

$ composer require masterminds/html5

If the parsed content is HTML5 (it starts with <!doctype html>), then the DomCrawler component will use that library automatically.

Be trained by Symfony experts - 2019-04-25 Lille - 2019-04-25 Clichy - 2019-04-29 Clichy

About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Find us on Twitter

Find us on Facebook