Skip to content
Researched developer tool comparisonsPrices dated · vendor sources linked · no star ratings
Search

Stage 01 · Write · Researched comparison

Best PHP HTML Parsers in 2026

The PHP DOM extension is the first pick for most teams. It ships with PHP, needs no Composer package, and PHP 8.4 adds a spec-compliant HTML5 parser through Dom\HTMLDocument. Symfony DomCrawler suits projects that already use Symfony components and want CSS-selector queries. masterminds/html5-php is the better choice when you need strict HTML5 parsing on older PHP versions or want to convert fragments to valid HTML5.

By
Published 27 Nov 2026 · 6 tools compared

We run no ads and no affiliate links at launch. The order of a list follows our published method. See how we score.

Prices are the starting prices vendors list publicly. Plans change, so confirm the current price on the vendor page before you buy.

Key takeaways

  • The PHP DOM extension is free, bundled with PHP, and its Dom\HTMLDocument class in PHP 8.4 parses according to the HTML5 spec.
  • Symfony DomCrawler, masterminds/html5-php, voku/simple_html_dom, DiDOM and QueryPath are all open-source and free to use.
  • DiDOM and simple_html_dom offer CSS-selector style queries, while the DOM extension and DomCrawler use XPath or their own selector APIs.
  • All six options run locally in your PHP process, so parsed markup never leaves your server.

Who each pick is for

Comparison

The 6 tools at a glance
ToolBest forStandout featureListed starting priceFree plan or trial
1PHP DOM extension (Dom\HTMLDocument)Teams that want a parser with no extra dependencyBundled with PHPFreeFree plan
2Symfony DomCrawlerSymfony projects that need CSS and XPath queriesCSS-selector and XPath supportFree (open source)Free plan
3masterminds/html5-phpStrict HTML5 parsing and serialization on any PHP versionImplements the HTML5 parsing algorithmFree (open source)Free plan
4voku/simple_html_domQuick scraping with jQuery-style selectorsjQuery-like selector APIFree (open source)Free plan
5DiDOMCSS-selector queries over a native DOMDocument treeCSS selectors with XPath conversionFree (open source)Free plan
6QueryPath (gravitypdf/querypath)jQuery-style traversal over HTML and XMLChainable jQuery-like APIFree (open source)Free plan

How we picked

We picked parsers that are currently maintained and genuinely parse HTML in PHP. Criteria were fit for common jobs (scraping, sanitizing, testing), supported PHP versions, licence and price, whether parsing runs locally, and known limits such as speed or missing selector support. Sources are vendor documentation, project repositories and public package pages. Prices and version requirements change, so confirm details on the vendor or repository page before you commit.

The tools, one by one

01

PHP DOM extension (Dom\HTMLDocument)

Best for teams that want a parser with no extra dependency

Visit php.net
PHP DOM extension (Dom\HTMLDocument) homepage
PHP DOM extension (Dom\HTMLDocument) homepage, captured Nov 2026

What it is and where it fits

The DOM extension is compiled into PHP by default, so there is nothing to install. Before PHP 8.4, DOMDocument::loadHTML parsed markup with a lenient, non-standard algorithm that mishandles some HTML5 elements and nesting. PHP 8.4 introduced Dom\HTMLDocument, which follows the HTML5 parsing algorithm and produces a spec-compliant tree. It also adds Dom\XMLDocument for XML.

You query the tree with XPath or by walking nodes. The API is verbose compared with CSS-selector libraries, and error handling relies on libxml's internal error buffer. For new projects on PHP 8.4 or later, this is the lowest-dependency option. Teams stuck on older PHP versions should expect quirks with malformed markup and HTML5-only tags.

Standout: Bundled with PHP

Pricing pointer

Free, as listed by the vendor (PHP DOM extension (Dom\HTMLDocument) website). Confirm the current plan price before you buy.

Free plan. Plans change, so confirm on the vendor's pricing page before you buy.

Benefits

  • Bundled with PHP
  • HTML5-compliant parsing in PHP 8.4
  • XPath support

Drawbacks

  • Older DOMDocument HTML parsing is lenient and not spec-compliant
  • verbose API

Skip it if this limit matters to you: older DOMDocument HTML parsing is lenient and not spec-compliant.

Verdict. A sensible pick for teams that want a parser with no extra dependency.

Alternatives in this guide: Symfony DomCrawler, masterminds/html5-php, voku/simple_html_dom

02

Symfony DomCrawler

Best for symfony projects that need CSS and XPath queries

Visit symfony.com
Symfony DomCrawler homepage
Symfony DomCrawler homepage, captured Nov 2026

What it is and where it fits

DomCrawler is a standalone Symfony component, installable with Composer as symfony/dom-crawler. It wraps DOMDocument and adds a Crawler object with filter() for CSS selectors and filterXPath() for XPath. It also exposes form and link helpers, which helps when scraping or testing pages.

It requires PHP 8.1 or later for current releases and depends on symfony/css-selector for CSS queries. The component does not replace DOMDocument's parser, so HTML5 edge cases behave the same as the underlying extension. It suits teams already using Symfony or PHPUnit-style functional tests. If you only need to pull a few values from well-formed HTML, the dependency footprint may be more than you want.

Standout: CSS-selector and XPath support

Pricing pointer

Free (open source), as listed by the vendor (Symfony DomCrawler website). Confirm the current plan price before you buy.

Free plan. Plans change, so confirm on the vendor's pricing page before you buy.

Benefits

  • CSS-selector and XPath support
  • works with forms and links
  • well documented

Drawbacks

  • Pulls in Symfony component dependencies
  • needs a PSR-4 autoloader

Skip it if this limit matters to you: pulls in Symfony component dependencies.

Verdict. A sensible pick for symfony projects that need CSS and XPath queries.

Alternatives in this guide: PHP DOM extension (Dom\HTMLDocument), masterminds/html5-php, voku/simple_html_dom

03

masterminds/html5-php

Best for strict HTML5 parsing and serialization on any PHP version

Visit github.com
masterminds/html5-php homepage
masterminds/html5-php homepage, captured Nov 2026

What it is and where it fits

This library is a pure-PHP implementation of the HTML5 parsing algorithm. It parses documents and fragments into a DOM tree and can serialize back to valid HTML5, which is useful for cleaning up malformed markup before storage. It runs on PHP 5.3 and later, so it works on legacy stacks where Dom\HTMLDocument is unavailable.

Install it with Composer as masterminds/html5. Because it is written in PHP rather than C, it is slower than the native extension on large documents. It gives you a DOMDocument-compatible tree, so you still query with XPath or add a selector library on top. Choose it when spec compliance matters more than raw speed, or when you need to run on PHP versions before 8.4.

Standout: Implements the HTML5 parsing algorithm

Pricing pointer

Free (open source), as listed by the vendor (masterminds/html5-php website). Confirm the current plan price before you buy.

Free plan. Plans change, so confirm on the vendor's pricing page before you buy.

Benefits

  • Implements the HTML5 parsing algorithm
  • converts fragments to valid HTML5
  • works on older PHP

Drawbacks

  • Slower than the native extension
  • no CSS-selector layer of its own

Skip it if this limit matters to you: slower than the native extension.

Verdict. A sensible pick for strict HTML5 parsing and serialization on any PHP version.

Alternatives in this guide: PHP DOM extension (Dom\HTMLDocument), Symfony DomCrawler, voku/simple_html_dom

04

voku/simple_html_dom

Best for quick scraping with jQuery-style selectors

Visit github.com
voku/simple_html_dom homepage
voku/simple_html_dom homepage, captured Nov 2026

What it is and where it fits

This is a maintained fork of the original simple_html_dom library. It provides a familiar API: find() takes CSS-style selectors, and you read text, attributes or inner HTML from matched elements. It parses messy real-world markup without throwing, which makes it popular for scraping.

Install it with Composer as voku/simple_html_dom. It requires PHP 7.0 or later for recent releases. The library keeps its own node objects rather than exposing DOMDocument nodes directly, so code written against the DOM extension does not transfer. It is a reasonable pick for small scraping scripts. For large documents or strict HTML5 handling, the native extension or html5-php is a better fit.

Standout: jQuery-like selector API

Pricing pointer

Free (open source), as listed by the vendor (voku/simple_html_dom website). Confirm the current plan price before you buy.

Free plan. Plans change, so confirm on the vendor's pricing page before you buy.

Benefits

  • jQuery-like selector API
  • handles malformed HTML
  • string and DOM output

Drawbacks

  • Fork of an unmaintained original
  • API differs from the DOM extension

Skip it if this limit matters to you: fork of an unmaintained original.

Verdict. A sensible pick for quick scraping with jQuery-style selectors.

Alternatives in this guide: PHP DOM extension (Dom\HTMLDocument), Symfony DomCrawler, masterminds/html5-php

05

DiDOM

Best for cSS-selector queries over a native DOMDocument tree

Visit github.com
DiDOM homepage
DiDOM homepage, captured Nov 2026

What it is and where it fits

DiDOM wraps DOMDocument and adds a selector engine that converts CSS selectors to XPath. Recent versions accept both the legacy DOMDocument and the PHP 8.4 Dom\HTMLDocument as input, so you can keep the native parser and get a friendlier query API. It also supports XML documents.

Install it with Composer as imangazaliev/didom. The API is small: create a Document, call find() with a CSS selector, then read text() or attributes. It does not include form or link helpers, so scraping workflows that need those should look at DomCrawler. The project is actively maintained but has a smaller user base, which means fewer third-party examples when you hit an edge case.

Standout: CSS selectors with XPath conversion

Pricing pointer

Free (open source), as listed by the vendor (DiDOM website). Confirm the current plan price before you buy.

Free plan. Plans change, so confirm on the vendor's pricing page before you buy.

Benefits

  • CSS selectors with XPath conversion
  • supports DOMDocument and Dom\HTMLDocument input
  • simple API

Drawbacks

  • Smaller community than Symfony DomCrawler
  • fewer helpers for forms and links

Skip it if this limit matters to you: smaller community than Symfony DomCrawler.

Verdict. A sensible pick for CSS-selector queries over a native DOMDocument tree.

Alternatives in this guide: PHP DOM extension (Dom\HTMLDocument), Symfony DomCrawler, masterminds/html5-php

06

QueryPath (gravitypdf/querypath)

Best for jQuery-style traversal over HTML and XML

Visit github.com
QueryPath (gravitypdf/querypath) homepage
QueryPath (gravitypdf/querypath) homepage, captured Nov 2026

What it is and where it fits

QueryPath provides a chainable interface modeled on jQuery. You load a document, then chain methods like find(), children() and text() to walk the tree and extract data. It handles both HTML and XML, and it has an extension mechanism for custom methods.

The original QueryPath project is no longer active. The gravitypdf/querypath fork is the maintained version, installable with Composer. It builds on DOMDocument, so parsing behavior follows the native extension. The chainable style is pleasant for traversal-heavy code but adds a learning curve, and documentation for the fork is thinner than for the original. It suits teams with existing QueryPath code or a preference for jQuery-style APIs.

Standout: Chainable jQuery-like API

Pricing pointer

Free (open source), as listed by the vendor (QueryPath (gravitypdf/querypath) website). Confirm the current plan price before you buy.

Free plan. Plans change, so confirm on the vendor's pricing page before you buy.

Benefits

  • Chainable jQuery-like API
  • works on HTML and XML
  • extension system

Drawbacks

  • Original project is inactive, so rely on the maintained fork
  • heavier API to learn

Skip it if this limit matters to you: original project is inactive, so rely on the maintained fork.

Verdict. A sensible pick for jQuery-style traversal over HTML and XML.

Alternatives in this guide: PHP DOM extension (Dom\HTMLDocument), Symfony DomCrawler, masterminds/html5-php

Who should use what

If you are starting a new project on PHP 8.4, use the native Dom\HTMLDocument and skip the dependency. If your codebase already uses Symfony components and you need CSS selectors plus form helpers, add DomCrawler. If you must run on PHP 7.x or need strict HTML5 serialization, choose masterminds/html5-php. For quick scraping scripts where malformed markup is common, voku/simple_html_dom or DiDOM gives you a short selector-based API. Teams with existing QueryPath code should stay on the gravitypdf fork.

Questions to settle before you buy

What to check before you buy

  • Confirm the parser supports your PHP version, especially if you are below PHP 8.4.
  • Check whether you need CSS selectors, XPath, or both, and pick a library that covers it.
  • Test the parser against real malformed markup from your target sites, not just clean samples.
  • Review the licence and whether the project has recent commits and releases.
  • Measure parse time on your largest documents, since pure-PHP parsers are slower than the C extension.

FAQ

Do I need a library if PHP already has DOM?

No. The DOM extension is bundled with PHP and, from PHP 8.4, includes a spec-compliant HTML5 parser through Dom\HTMLDocument. Add a library only when you want CSS selectors, form helpers or HTML5 parsing on older PHP versions.

Which parser handles malformed HTML best?

masterminds/html5-php implements the HTML5 parsing algorithm and handles malformed markup predictably. voku/simple_html_dom is also tolerant and rarely throws on broken markup. The native DOMDocument parser before PHP 8.4 is lenient but not spec-compliant.

Can I use CSS selectors with the DOM extension?

Not directly. The DOM extension uses XPath. To query with CSS selectors, add Symfony DomCrawler, DiDOM or voku/simple_html_dom, all of which convert selectors to XPath or provide their own matching.

Are these parsers safe for private HTML?

Yes. All six run inside your PHP process, so the markup you parse stays on your server. This differs from online HTML formatters or validators, where you should never paste secrets, tokens or production data.

Is paquettg/php-html-parser still a good choice?

The project has not seen active maintenance for some time, so we left it out. For new code, use the native extension, Symfony DomCrawler or DiDOM instead, all of which are maintained.

Sources we checked

Method: how we score · editorial policy.

  1. PHP DOM extension (Dom\HTMLDocument) (official site)
  2. Symfony DomCrawler (official site)
  3. masterminds/html5-php (official site)
  4. voku/simple_html_dom (official site)
  5. DiDOM (official site)
  6. QueryPath (gravitypdf/querypath) (official site)

Change log. First published 27 Nov 2026.