Download the PHP package diffen/justhtml without Composer

On this page you can find all versions of the php package diffen/justhtml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package justhtml

JustHTML for PHP

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

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. Its C implementation is faster and is a better fit for many projects.

Choose JustHTML when you need one or more of these:

For most tasks, start with the full parser shown below. The parsing guide explains when targeted extraction is worthwhile.

Requirements

Installation

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):

Quickstart

Expected output:

Text extraction

toText() returns normalized human-readable text. textContent returns the exact text stored in the parsed DOM:

Output:

toText() concatenates DOM text first, collapses HTML whitespace runs to one space, and trims the complete result. It takes no arguments.

The read-only textContent property follows the DOM Node.textContent contract. It does not trim, collapse whitespace, or add separators at element boundaries. It includes script, style, and hidden text; br and block elements do not add line breaks. Document and doctype nodes return null. Template contents are available through $template->templateContent->textContent, not $template->textContent.

Run examples/text.php for a complete example of normalized text, DOM text content, and template content.

CSS selectors

Input HTML:

Expected output:

Multiple selectors (comma-separated):

Expected output:

Markdown

Note: toMarkdown() is a convenience helper (best-effort conversion) and not part of the HTML specification.

Detailed example (Wikipedia Earth)

The script loads examples/fixtures/wikipedia-earth.html and prints a walkthrough of selectors, attributes, classes, inner/outer HTML, text, and Markdown extraction.

Choosing a parsing API

For most crawling tasks, use the full parser shown in the quickstart. Choose Stream::select() only when you need one or a few known matches and want to avoid unnecessary work after finding them. Stop iteration to stop parsing:

This optimized path trades flexibility for lower work and memory: it supports a documented subset of CSS selectors, may offer little benefit when a match is late or absent, and returns nodes that should be treated as read-only while the generator is active. Like the full parser, it accepts a complete in-memory HTML string or byte buffer; it does not stream a network response or file in chunks.

See Streaming.md for a task-based decision guide, selector support, risks, encoding options, and the lower-level event API for specialized scanners.

CLI

For more detailed examples, see CLI.md.

For basic first-result extractions, the CLI automatically chooses a significantly faster parsing method when appropriate.

More examples:

Comparison to other parsers

Compliance results use the html5lib tree-construction tests. Performance results use a 1,000-document Common Crawl fixture set and report average milliseconds per document (lower is better). Compliance was verified and performance rerun on 2026-07-22 using PHP 8.5.8 with libxml 2.9.13.

Parser Spec compliance (html5lib-tests pass rate) Speed: Avg ms/doc (lower is better) Selectors Notes
JustHTML 1770/1770 (100%) 4.03 CSS Full spec compliance
DOM\HTMLDocument 873/1770 (49.3%) 0.45 CSS PHP built-in DOM extension (DOM\HTMLDocument; HTML5 parser in PHP 8.4+, C implementation)
DOMDocument (libxml) 54/1770 (3.1%) 0.77 XPath Legacy HTML parser (libxml2), not HTML5-correct
masterminds/html5 75/1770 (4.2%) 3.50 XPath HTML5 parser, low compliance
voku/simple_html_dom 29/1770 (1.6%) 2.08 CSS Lenient DOM wrapper, low compliance
symfony/dom-crawler 54/1770 (3.1%) 3.38 CSS/XPath Wrapper over DOMDocument (libxml)

See the benchmark guide for dependencies, reproduction commands, methodology, and historical results.

Lead paragraph extraction benchmark

This benchmark parses the bundled Wikipedia Earth fixture and extracts its first non-empty lead paragraph.

Example results (PHP 8.5.8, rerun 2026-07-22, 5-run average; all outputs match the JustHTML baseline):

Parser Average time (milliseconds) Total time (seconds) Iterations
JustHTML 56.44 0.28 5
JustHTML (Stream::select) 25.75 0.13 5
DOM\HTMLDocument 6.90 0.03 5
DOMDocument (libxml) 9.94 0.05 5
masterminds/html5 45.89 0.23 5
voku/simple_html_dom 116.09 0.58 5
symfony/dom-crawler 46.64 0.23 5

For this selective early-result workload, Stream::select() was 2.19× faster than JustHTML's full-parser path and used 99.3% fewer retained parser nodes in a controlled memory proxy. The complete input string remains in memory with both APIs. These gains are most relevant when a crawler needs a small number of early matches; late, absent, or broad matches can erase the advantage. See the benchmark guide for the protocol and detailed results.

Tests

Test against multiple PHP versions via Docker:

Notes


All versions of justhtml with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-mbstring Version *
ext-iconv Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package diffen/justhtml contains the following files

Loading the files please wait ...