PHPackages                             wikimedia/html-formatter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wikimedia/html-formatter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wikimedia/html-formatter
========================

Performs transformations of HTML by wrapping around libxml2 and working around its countless bugs.

4.1.0(2y ago)7802.1k↑27%21GPL-2.0-or-laterPHPPHP &gt;=7.4.3

Since Apr 7Pushed 2mo ago15 watchersCompare

[ Source](https://github.com/wikimedia/HtmlFormatter)[ Packagist](https://packagist.org/packages/wikimedia/html-formatter)[ Docs](https://www.mediawiki.org/wiki/HtmlFormatter)[ RSS](/packages/wikimedia-html-formatter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (13)Used By (1)

HtmlFormatter is a library spun off MediaWiki that allows you to load HTML into DomDocument, perform manipulations on it, and then return a HTML string.

Usage
-----

[](#usage)

```
use HtmlFormatter\HtmlFormatter;
// Load HTML that already has doctype and stuff
$formatter = new HtmlFormatter( $html );

// ...or one that doesn't have it
$formatter = new HtmlFormatter( HtmlFormatter::wrapHTML( $html ) );

// Add rules to remove some stuff
$formatter->remove( 'img' );
$formatter->remove( [ '.some_css_class', '#some_id', 'div.some_other_class' ] );
// Only the above syntax is supported, not full CSS/jQuery selectors

// These tags get replaced with their inner HTML,
// e.g. &lt;tag>foo&lt;/tag> --> foo
// Only tag names are supported here
$formatter->flatten( 'span' );
$formatter->flatten( [ 'code', 'pre' ] );

// Actually perform the removals
$formatter->filterContent();

// Direct DomDocument manipulations are possible
$formatter->getDoc()->createElement( 'p', 'Appended paragraph' );

// Get resulting HTML
$processedHtml = $formatter->getText();
```

License
-------

[](#license)

Copyright 2011-2024 MediaWiki contributors

Released under the GNU General Public License version 2, see `COPYING`.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance57

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~263 days

Recently: every ~95 days

Total

12

Last Release

796d ago

Major Versions

1.0.2 → 2.0.02020-07-25

2.0.1 → 3.0.02021-03-04

3.0.1 → 4.0.02023-02-24

PHP version history (3 changes)1.0.0PHP &gt;=5.5

2.0.0PHP &gt;=7.2.9

4.0.0PHP &gt;=7.4.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

---

Top Contributors

[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (18 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (12 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (11 commits)")[![MaxSem](https://avatars.githubusercontent.com/u/1260606?v=4)](https://github.com/MaxSem "MaxSem (11 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (5 commits)")[![edg2s](https://avatars.githubusercontent.com/u/180672?v=4)](https://github.com/edg2s "edg2s (4 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (4 commits)")[![hashar](https://avatars.githubusercontent.com/u/281689?v=4)](https://github.com/hashar "hashar (2 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (2 commits)")[![Func86](https://avatars.githubusercontent.com/u/22788371?v=4)](https://github.com/Func86 "Func86 (1 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (1 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (1 commits)")[![ebernhardson](https://avatars.githubusercontent.com/u/558434?v=4)](https://github.com/ebernhardson "ebernhardson (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-html-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/wikimedia-html-formatter/health.svg)](https://phpackages.com/packages/wikimedia-html-formatter)
```

###  Alternatives

[fojuth/readmegen

Readme file / doc generator. It uses VCS logs as a source of information.

6230.7k](/packages/fojuth-readmegen)[fintara/calculator-php

Calculator for arithmetic expressions

1331.2k](/packages/fintara-calculator-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
