PHPackages                             timgws/cleanhtml - 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. timgws/cleanhtml

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

timgws/cleanhtml
================

Quickly &amp; Easily clean out HTML text, making sure that only the bare minimum is left behind

61152PHP

Since Mar 11Pushed 10y ago1 watchersCompare

[ Source](https://github.com/timgws/CleanHTML)[ Packagist](https://packagist.org/packages/timgws/cleanhtml)[ RSS](/packages/timgws-cleanhtml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

CleanHTML
=========

[](#cleanhtml)

[![Test Coverage](https://camo.githubusercontent.com/a764ededee232bf65404977a33b0a3d4db25ef38320ec8ec509fa6a013a9ed93/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f74696d6777732f436c65616e48544d4c2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/timgws/CleanHTML/coverage)[![Code Climate](https://camo.githubusercontent.com/6089370ab32394fe0227507c4dac552aac4a535706992991f9a94f709c4b3a66/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f74696d6777732f436c65616e48544d4c2f6261646765732f6770612e737667)](https://codeclimate.com/github/timgws/CleanHTML)

Making HTML clean since late 2012!

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

[](#requirements)

- PHP 5.2+
- php-xml

How to install
--------------

[](#how-to-install)

```
    composer require timgws/cleanhtml

```

How to use
----------

[](#how-to-use)

```
use timgws\CleanHTML\CleanHTML;
$tidy = new CleanHTML();
$output = $tidy->clean('I need a shower. I am dirty HTML.');
```

$output should now contain:

```
I need a shower. I am dirty HTML.
```

Using the Clean function will remove tables, any Javascript or other non-friendly items that you might not want to see from user submitted HTML.

If you want to see some examples, the best place to look would be [some of the CleanHTML test](https://github.com/timgws/CleanHTML/blob/master/tests/CleanHTMLTest.php)

What does it do?
----------------

[](#what-does-it-do)

1. Removed additional spaces from HTML
2. Replaces multiple `` tags with paragraph tags
3. Removes any `` tags
4. Renames any `` tags to ``
5. Changes `` tags to ``
6. Replaces `` with just `` tags
7. Removes weird `` tags
8. Uses HTML purifier to only allow h1,h2,h3,h4,h5,p,strong,b,ul,ol,li,hr,pre,code tags
9. Runs steps 3-&gt;7 one more time, just to catch anything that might have missed by allowed tags
10. Outputs nice clean HTML \\o/

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

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

---

Top Contributors

[![timgws](https://avatars.githubusercontent.com/u/1050232?v=4)](https://github.com/timgws "timgws (45 commits)")

### Embed Badge

![Health badge](/badges/timgws-cleanhtml/health.svg)

```
[![Health](https://phpackages.com/badges/timgws-cleanhtml/health.svg)](https://phpackages.com/packages/timgws-cleanhtml)
```

PHPackages © 2026

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