PHPackages                             eugenecooper/purify - 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. eugenecooper/purify

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

eugenecooper/purify
===================

An HTML Purifier for Laravel 5

1.1.2(8y ago)132MITPHPPHP &gt;=5.4.0

Since May 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/eugenecooper/purify)[ Packagist](https://packagist.org/packages/eugenecooper/purify)[ RSS](/packages/eugenecooper-purify/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (0)

Purify
======

[](#purify)

[![Travis CI](https://camo.githubusercontent.com/0e93b490b878681e38258c55adcb185fc2b2beeaf599365736343910300252aa/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73746576656261756d616e2f7075726966792e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/stevebauman/purify)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3646cbf1ceec057ce4e030556892ee4ac4bb97f9f2a451bf72d0146299740638/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73746576656261756d616e2f7075726966792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/stevebauman/purify/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/ab3dbef7c0a0cca820979bba38633738077b1f5b57e99c3d8c9a45926e27c6a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746576656261756d616e2f7075726966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevebauman/purify)[![Total Downloads](https://camo.githubusercontent.com/9cb4b9dbccc1fafc1f1c0f6ade8e15fe9b03ce148b74bb75f5cf1025a22bc1dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746576656261756d616e2f7075726966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevebauman/purify)[![License](https://camo.githubusercontent.com/9f6691c0404271bf063c53b4a0ee8f4d2baacb26c263f074c87df1ff33e8fc79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73746576656261756d616e2f7075726966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevebauman/purify)

### Description

[](#description)

Purify is an HTML Purifier helper for Laravel 5. It utilizes the fantastic package [HTMLPurifier](https://github.com/ezyang/htmlpurifier)by [ezyang](https://github.com/ezyang). All credit for purification goes to him.

### Installation

[](#installation)

To install Purify, insert the following require in your `composer.json` file:

```
"stevebauman/purify": "1.1.*"

```

Now run a `composer update` on your project source.

Once that's finished, insert the service provider in your `app/config/app.php`(or `config/app.php` for Laravel 5) configuration file:

```
'Stevebauman\Purify\PurifyServiceProvider'

```

You can also use the facade if you wish:

```
'Purify' => 'Stevebauman\Purify\Facades\Purify'

```

### Usage

[](#usage)

##### Cleaning a String

[](#cleaning-a-string)

To clean a users input, simply use the clean method:

```
$input = 'alert("Harmful Script"); Test';

$cleaned = Purify::clean($input);

echo $cleaned; // Returns 'Test'
```

##### Cleaning an Array

[](#cleaning-an-array)

Need to purify an array of user input? Just pass in an array:

```
$inputArray = [
    'alert("Harmful Script"); Test',
    'alert("Harmful Script"); Test',
];

$cleaned = Purfiy::clean($inputArray);

var_dump($cleaned); // Returns [0] => 'Test' [1] => 'Test'
```

##### Dynamic Configuration

[](#dynamic-configuration)

Need to add or modify rules for a single input? Pass in a configuration array into the second parameter:

```
$configuration = ['HTML.Allowed' => 'div,b,a[href]'];

$cleaned = Purify::clean($input, $configuration);
```

> **Note**: Configuration passed into the second parameter is merged with the current configuration and will overwrite array keys you supply. This allows you to add settings on the fly. Simply pass `false` into the third parameter if you **do not** want the configuration merged.

```
$configuration = ['HTML.Allowed' => 'div,b,a[href]'];

$cleaned = Purify::clean($input, $configuration, $merge = false);
```

##### Replacing the HTML Purifier instance

[](#replacing-the-html-purifier-instance)

Need to replace the HTML Purifier instance with your own? Call the `setPurifier()` method:

```
$purifier = new HTMLPurifier();

Purify::setPurifier($purifier);
```

##### Replacing the HTML Purifier Configuration instance

[](#replacing-the-html-purifier-configuration-instance)

Need to replace the HTML Purifier Configuration instance with your own? Call the `setPurifierConfig()` method:

```
$settings = ['HTML.Allowed' => 'div,b,a[href]'];

$configuration = new HTMLPurifier_Config($settings);

Purify::setPurifierConfig($configuration);
```

### Configuration

[](#configuration)

Inside the configuration file, the entire settings array is passed directly to the HTML Purifier configuration, so feel free to customize it however you wish. For the configuration documentation, please visit the HTML Purifier Website:

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 98.2% 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 ~197 days

Total

5

Last Release

3236d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/75191f939aee64e753855a3601c2180ba3d8242fe06139929e1a431c67fd2cda?d=identicon)[eugenecooper](/maintainers/eugenecooper)

---

Top Contributors

[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (54 commits)")[![eugenecooper](https://avatars.githubusercontent.com/u/8261869?v=4)](https://github.com/eugenecooper "eugenecooper (1 commits)")

---

Tags

laravelhtmlPurifiercleanpurifycleanerpurification

### Embed Badge

![Health badge](/badges/eugenecooper-purify/health.svg)

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

###  Alternatives

[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[xemlock/htmlpurifier-html5

HTML5 support for HTML Purifier

1052.9M11](/packages/xemlock-htmlpurifier-html5)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[illuminatech/validation-composite

Allows uniting several validation rules into a single one for easy re-usage

184485.5k](/packages/illuminatech-validation-composite)

PHPackages © 2026

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