thesoftwarefanatics/php-html-parser
A PHP HTML parser for loading, traversing, and manipulating HTML documents. It provides a simple API for extracting elements, attributes, and text, making it useful for scraping, DOM-style processing, and HTML cleanup in PHP applications.
composer require something and move on. The 1.8.1 release is a useful forcing function: it reopens a decision that was probably made by default and gives the team a concrete, dated artifact to evaluate instead of a stale one.<article> bodies out of old markup), HTML rewriting pipelines (email templates, AMP variants, link rewriting, image srcset injection), third-party feed/partner-page ingestion, markup QA and SEO audits (assert every page has exactly one <h1>, canonical tag, alt text), and test assertions against rendered Blade output.Reasonable to consider when:
$html->find('.price', 0)) and your team already knows it.Look elsewhere when:
DOMDocument is HTML4-ish and mangles modern markup; masterminds/html5 (used by Symfony's DomCrawler) handles it properly.symfony/dom-crawler plus Laravel's Http client is the well-trodden path, is maintained, and covers CSS selectors, form submission, and links. Upstream paquette/php-html-parser is the same idea with a real user base. For JS-rendered pages, no PHP parser helps — that's Laravel Panther or a headless browser.What 1.8.1 changes about the evaluation (patch release, no new features):
replaceChild fix and the "ignore ; or space after charset in <meta>" fix change output for real inputs — DOM mutation results and detected document encoding respectively. Any existing migration script that depends on current output should be re-run against a fixture corpus before bumping.To executives: HTML parsing is plumbing that enables a set of content features — migration off the legacy CMS, partner-feed ingestion, markup QA — none of which are differentiators but all of which are on the roadmap. The capability is cheap to acquire; the only real cost is choosing well. This library just shipped its first patch release in years: bug fixes, a broader test suite, and a couple of new contributors. That's encouraging and worth a cheap trial for internal tooling, but it isn't a maintenance guarantee, so the recommendation is unchanged: trial it behind an abstraction layer for internal tools only, and standardize on a maintained parser (Symfony DomCrawler + HTML5) for anything customer-facing or security-sensitive. Net cost of the cautious path is roughly a day of engineering; net cost of the careless path is an unpatched parser sitting in a trust boundary.
To engineering: The API is genuinely pleasant — load a string, find() with CSS selectors, mutate, serialize. That's the whole value proposition, and it's worth 30 minutes of evaluation. 1.8.1 is a real but modest signal: six merged PRs, four contributors, expanded CI, and fixes to replaceChild and <meta charset> parsing. Treat that as "someone is watching the repo," not "this is maintained." Concretely: (1) define a small HtmlDocument interface in our own namespace and bind this package behind it; (2) pin the exact version and add a test suite covering the selectors and mutation operations we actually use, so both the 1.8.1 bump and any future swap are verifiable — the replaceChild and charset fixes make this non-optional if we're already on 1.8.x; (3) don't route user-supplied HTML through it — use masterminds/html5 or a dedicated sanitizer; (4) benchmark memory on a representative 5–10MB page before committing to bulk ingestion. If any of those four checks is inconvenient, that's the signal to reach for DomCrawler now and skip the experiment.
How can I help you explore Laravel packages today?