Skip to content

Releases: a19836/php-html-dom-lib

PHP HTML DOM Lib - v1

17 Dec 17:36

Choose a tag to compare

PHP HTML DOM Lib is a library designed to parse, inspect, and manipulate HTML content using a DOM-based approach.
It provides a high-level API on top of PHP’s DOM engine, making it easy to read, modify, query, and rewrite HTML documents programmatically.

The library can detect whether a given input contains valid HTML and safely handle both raw text and structured HTML/XML content. Once loaded, it exposes the underlying DOMDocument while also offering convenient helper methods to simplify common DOM operations.

With this library, you can:

  • Detect whether a string contains HTML content
  • Access and work directly with the underlying DOMDocument
  • Traverse and iterate DOM nodes
  • Query elements using tag names or CSS selectors
  • Read and modify element styles and attributes
  • Generate CSS selectors for DOM nodes
  • Retrieve and modify inner HTML and outer HTML
  • Remove DOM elements safely
  • Resize images based on width and height attributes defined in HTML
  • Work with inline images (base64), including decoding, extracting metadata, and saving them to files
  • Export the modified HTML as encoded or exact (non-encoded) output

The library supports modern DOM manipulation patterns such as querySelector and querySelectorAll, enabling familiar and expressive HTML queries similar to those found in frontend JavaScript environments.

This library is ideal for content processing, HTML sanitization, email template manipulation, web scraping preparation, WYSIWYG editors, and server-side HTML transformations.