Download the PHP package daniesy/dominator without Composer
On this page you can find all versions of the php package daniesy/dominator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download daniesy/dominator
More information about daniesy/dominator
Files in daniesy/dominator
Download daniesy/dominator
More information about daniesy/dominator
Files in daniesy/dominator
Vendor daniesy
Package dominator
Short Description A simple HTML parser for PHP.
License MIT
Homepage https://github.com/daniesy/dominator
Package dominator
Short Description A simple HTML parser for PHP.
License MIT
Homepage https://github.com/daniesy/dominator
Please rate this library. Is it a good library?
Informations about the package dominator
DOMinator
A robust, fast, and fully-featured HTML5 parser and query engine for PHP. Parse, traverse, manipulate, and query HTML documents with ease, supporting all modern HTML5 features, error recovery, namespaces, and more.
Features
- Full HTML5 parsing: Handles all standard HTML5 elements, void/self-closing tags, comments, CDATA, script/style content, and multiple doctype variants.
- XML declaration support: Preserves and exports XML declarations (e.g.,
<?xml version="1.0" encoding="utf-8"?>) at the start of the document. - Error recovery: Gracefully parses malformed or broken HTML, just like browsers do.
- Entity decoding: Decodes HTML entities in text and attributes.
- Whitespace normalization: Optionally normalizes whitespace in text nodes.
- Namespaces: Supports XML/HTML namespaces (e.g.,
svg:rect). - Attribute handling: Handles quoted/unquoted and boolean attributes.
- Query engine: Powerful CSS-like selectors for finding nodes (call
querySelectorAll,querySelector, orgetElementsByTagNamedirectly on anyNode). - Node manipulation: Add, remove, set attributes, change text, and more (
Node). - Performance: Optimized for large and deeply nested documents.
- Comprehensive tests: Includes extensive tests for all features and edge cases.
- Robust CSS parser: Parses CSS rules and at-rules (including nested and simple at-rules like
@mediaand@font-face). - CSS inlining: Optionally inlines CSS styles as
styleattributes when exporting HTML (Node::toInlinedHtml). - Pretty-print and minify HTML: Export HTML as minified (default) or pretty-printed (indented, human-readable) with
Node::toHtml(false).
Installation
Install via Composer:
Or include the src/ files directly in your project.
Usage
Basic Parsing
Traversing the DOM
Querying with CSS Selectors (DOM-like)
Manipulating Nodes
CSS Parsing and Selector Matching
CssParser::parse($css)parses a CSS string into an array of rules and at-rules (including nested and simple at-rules).CssParser::matches($selector, $node)checks if a node matches a CSS selector (supports tag, class, id, compound, and descendant selectors).
Exporting Back to HTML
Handling Namespaces
Parsing Options
-
DOMinator::read($html, $normalizeWhitespace = false, $preprocess = null)- Parses the given HTML string into a DOM tree.
- Supports input with an XML declaration (e.g.,
<?xml ...?>). - New: Accepts an optional
$preprocesscallback. If provided, this function will be called with the HTML string before parsing. You can use this to preprocess, sanitize, or transform the HTML as needed. - Example:
Node::toHtml($minify = true)- If
$minifyisfalse, outputs pretty-printed HTML with indentation and newlines. - If
$minifyistrue(default), outputs minified HTML.
- If
Node::toInlinedHtml($minify = true)- Inlines simple CSS rules from