PHPackages                             diffen/justhtml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. diffen/justhtml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

diffen/justhtml
===============

Pure-PHP HTML5 parser (JustHTML port) with html5lib compliance

v0.3.0(3w ago)05MITPHPPHP &gt;=7.4

Since Feb 2Pushed 3w agoCompare

[ Source](https://github.com/diffen/justhtml-php)[ Packagist](https://packagist.org/packages/diffen/justhtml)[ RSS](/packages/diffen-justhtml/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (8)Versions (9)Used By (0)

JustHTML for PHP
================

[](#justhtml-for-php)

PHP HTML5 parser ported from [Emil Stenström's JustHTML](https://github.com/EmilStenstrom/justhtml), targeting PHP 7.4+. Inspired by [Simon Willison's JavaScript port, justjshtml](https://github.com/simonw/justjshtml). It is built for correctness and passes the html5lib test suite (tree builder, tokenizer, serializer, and encoding tests).

Why use JustHTML?
-----------------

[](#why-use-justhtml)

If you are on PHP 8.4+ and need to process a complete document, start with PHP's built-in [`DOM\\HTMLDocument`](https://www.php.net/manual/en/class.dom-htmldocument.php). Its C implementation is faster and is a better fit for many projects.

Choose JustHTML when you need one or more of these:

- Pure PHP support across PHP 7.4 through 8.5.
- Browser-like handling of malformed HTML.
- CSS selectors plus HTML, text, and Markdown extraction helpers.
- Targeted extraction of a few known elements without always parsing and retaining the complete document.

For most tasks, start with the full parser shown below. The [parsing guide](Streaming.md) explains when targeted extraction is worthwhile.

Requirements
------------

[](#requirements)

- PHP 7.4+ (tested with 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5)
- `ext-mbstring`
- `ext-iconv`

Installation
------------

[](#installation)

```
composer require diffen/justhtml
```

Non-Composer use: include `src/JustHTML/*.php` with your autoloader and keep `data/` alongside `src/`.

CLI via Homebrew (6.0.0+ requires a one-time trust step, which lets Homebrew run this MIT-licensed formula's install code):

```
brew trust --formula diffen/justhtml/justhtml
brew install diffen/justhtml/justhtml
```

Quickstart
----------

[](#quickstart)

```
