PHPackages                             p3k/html-sanitizer - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. p3k/html-sanitizer

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

p3k/html-sanitizer
==================

An HTML sanitizer with good defaults

0.1.2(3y ago)6435[1 issues](https://github.com/aaronpk/p3k-html-sanitizer/issues)MITPHP

Since Nov 29Pushed 3y ago2 watchersCompare

[ Source](https://github.com/aaronpk/p3k-html-sanitizer)[ Packagist](https://packagist.org/packages/p3k/html-sanitizer)[ Docs](https://github.com/aaronpk/p3k-html-sanitizer)[ RSS](/packages/p3k-html-sanitizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

p3k-html-sanitizer
==================

[](#p3k-html-sanitizer)

An HTML sanitizer with good defaults usable for displaying untrusted HTML in applications.

Allows only a basic set of formatting tags, removing all `` tags. Removes all attributes of allowed tags except leaves in Microformats 2 classes.

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

[](#installation)

```
composer require p3k/html-sanitizer

```

Usage
-----

[](#usage)

```
$output = p3k\HTML::sanitize($input);

```

### Options

[](#options)

There are a minimal number of options you can pass to the sanitize function:

```
$options = [
  'baseURL' => 'https://example.com/'
];

$output = p3k\HTML::sanitize($input, $options);

```

- `baseURL` - (default `false`)
- `allowImg` - (`true`/`false`, default `true`) - whether to allow `img` tags in the output
- `allowMf2` - (`true`/`false`, default `true`) - whether to allow Microformats 2 classes on elements
- `allowTables` - (`true`/`false`, default `false`) - whether to allow table elements (`table`, `thead`, `tbody`, `tr`, `td`)

Allowed Tags
------------

[](#allowed-tags)

The following HTML tags are the only tags allowed in the input. Everything else will be removed.

- `a`
- `abbr`
- `b`
- `br`
- `code`
- `del`
- `em`
- `i`
- `q`
- `strike`
- `strong`
- `time`
- `blockquote`
- `pre`
- `p`
- `h1`
- `h2`
- `h3`
- `h4`
- `h5`
- `h6`
- `ul`
- `li`
- `ol`
- `span`
- `hr`
- `img` - only if `$options['allowImg']` is `true`
- `table`, `thead`, `tbody`, `tfoot`, `tr`, `th`, `td` - only if `$options['allowTables']` is `true`

All attributes other than those below will be removed.

- `` - `href`
- `` - `src width height alt`
- `` - `datetime`

If `$options['allowMf2']` is `true`, class attributes will be removed, except for Microformats 2 class values.

For example:

`Hello`

will become

`Hello`

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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.

###  Release Activity

Cadence

Every ~543 days

Total

3

Last Release

1274d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/385b302aef27e9e72ddfbf65c8b15cfce5946744fe2e541c5b415665fc2351fc?d=identicon)[aaronpk](/maintainers/aaronpk)

---

Top Contributors

[![aaronpk](https://avatars.githubusercontent.com/u/113001?v=4)](https://github.com/aaronpk "aaronpk (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/p3k-html-sanitizer/health.svg)

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

###  Alternatives

[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[xemlock/htmlpurifier-html5

HTML5 support for HTML Purifier

1052.9M11](/packages/xemlock-htmlpurifier-html5)[chrisshick/cakephp3-html-purifier

This is a CakePHP3 Purifier Plugin Behavior that cleanses data before it is marshalled into the entity.

12168.1k](/packages/chrisshick-cakephp3-html-purifier)

PHPackages © 2026

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