Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Html5 Laravel Package

masterminds/html5

HTML5-PHP is a standards-compliant HTML5 parser and serializer written entirely in PHP. It includes both a DOM tree builder and an event-based SAX-like parser, supports PHP namespaces and Composer, interoperates with QueryPath, and requires PHP 7.4+. Stable and widely used in production.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy (buy): Any feature that requires reading or rewriting HTML in PHP should consume this library rather than hand-rolled regex or string manipulation. It converts an "engineering research project" into a Composer line item.
  • Content ingestion and normalization: CMS migrations, WYSIWYG output cleanup, cross-format conversion (HTML → DOM → HTML, HTML → PDF/email templates), and reconciling third-party HTML from partners or legacy systems.
  • Web scraping / aggregation features: Turning fetched pages into traversable DOMDocument trees for downstream extraction, enrichment, or deduplication.
  • Email and PDF rendering pipelines: Serializing DOM trees back to standards-compliant HTML5 so template engines and renderers (wkhtmltopdf, headless browsers, email clients) receive predictable markup.
  • Security and trust boundaries: Normalizing untrusted HTML before storage or display; pairing with a sanitizer to control what survives the parse/serialize round trip.
  • Roadmap leverage: A low-cost enabling component for roadmap items (importers, integrations, reporting exports) that would otherwise each require bespoke parsing code.

When to Consider This Package

Consider adopting when all of the following are true:

  • The stack is PHP 7.4+ and Composer-managed.
  • You need to parse real-world, malformed HTML (not well-formed XML) into a traversable tree, and/or serialize a DOM back to spec-shaped HTML5.
  • You want the output to be a native DOMDocument so existing DOM/XPath tooling, Symfony DomCrawler, or QueryPath can operate on it.
  • You value a mature, widely deployed dependency (5M+ downloads, sustained stability, MIT-style licensing) over a bespoke parser.
  • Your requirement is structure, not validation or rendering — you do not need to enforce spec conformance or execute scripts/CSS.

Look elsewhere (or supplement) when:

  • You need a validating parser — this one corrects some HTML but does not verify conformance.
  • You need to pause/mutate mid-parse — the parser is not re-entrant.
  • Your primary need is CSS-selector querying — use Symfony DomCrawler (which itself builds on this library) rather than calling the low-level API directly.
  • You're parsing XML or strict feeds — use a dedicated XML parser; HTML5 namespace semantics differ from XML.
  • You need JavaScript/CSS execution or visual rendering — this is a server-side parser, not a browser engine.
  • You're outside PHP — pick the ecosystem equivalent (html5lib, jsdom, BeautifulSoup) rather than bridging.

How to Pitch It (Stakeholders)

For executives: We need reliable HTML handling across several planned features (content import, email/PDF output, partner HTML ingestion). Rather than funding custom parsing code, we can adopt a mature open-source PHP library that is already used at scale — over five million downloads, a stable release cadence, and permissive licensing. It's low-risk, low-cost foundational infrastructure: it removes a recurring class of bugs and unblocks roadmap work without adding a vendor contract.

For engineering: This is the de facto HTML5 parser for PHP — spec-shaped tokenizer/serializer, DOMDocument output, SAX-style event API when we need custom traversal, and options for namespaces and entity encoding. It slots into Composer, plays well with Symfony DomCrawler and XPath, and is battle-tested in production. Trade-offs to note: it's non-validating, non-re-entrant, and not a rendering engine — so we pair it with a sanitizer for untrusted input and keep XML parsing separate. Net: we delete bespoke regex parsing, standardize on one parsing path, and inherit a well-understood maintenance profile.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc