PHPackages                             hdvinnie/laravel-html-purifier - 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. [Security](/categories/security)
4. /
5. hdvinnie/laravel-html-purifier

AbandonedArchivedPackage[Security](/categories/security)

hdvinnie/laravel-html-purifier
==============================

An HTML Purifier for Laravel

v3.0.0(2y ago)126.7kMITPHPPHP ^7.2|^8.0

Since Feb 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/HDVinnie/laravel-html-purifier)[ Packagist](https://packagist.org/packages/hdvinnie/laravel-html-purifier)[ Docs](https://github.com/HDVinnie/laravel-html-purifier)[ RSS](/packages/hdvinnie-laravel-html-purifier/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (0)

laravel-html-purifier
=====================

[](#laravel-html-purifier)

An HTML Purifier for Laravel

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist](https://camo.githubusercontent.com/eb46d9a988e273e431db73a11c2a726623cbf702957052f846aef72ea12072c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686476696e6e69652f6c61726176656c2d68746d6c2d7075726966696572)](https://packagist.org/packages/hdvinnie/laravel-html-purifier/)[![Packagist Downloads](https://camo.githubusercontent.com/5c3eea4c8ec30cc793e9d89c722e5b2ef363e59109c2f63e7868343891bb41f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f686476696e6e69652f6c61726176656c2d68746d6c2d70757269666965722e7376673f6c6162656c3d7061636b6167697374253230646f776e6c6f616473)](https://packagist.org/packages/hdvinnie/laravel-html-purifier)

A simple [Laravel](http://www.laravel.com/) service provider for easily using [HTMLPurifier](http://htmlpurifier.org/) inside Laravel. From their website:

> HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications. Tired of using BBCode due to the current landscape of deficient or insecure HTML filters? Have a WYSIWYG editor but never been able to use it? Looking for high-quality, standards-compliant, open-source components for that application you're building? HTML Purifier is for you!

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

[](#installation)

### For Laravel 5.5+

[](#for-laravel-55)

Require this package with composer:

```
composer require hdvinnie/laravel-html-purifier

```

The service provider will be auto-discovered. You do not need to add the provider anywhere.

### For Laravel 5.0 to 5.4

[](#for-laravel-50-to-54)

Require this package with composer:

```
composer require hdvinnie/laravel-html-purifier

```

Find the `providers` key in `config/app.php` and register the HTMLPurifier Service Provider.

```
    'providers' => [
        // ...
        HDVinnie\Purifier\PurifierServiceProvider::class,
    ]
```

Find the `aliases` key in `config/app.php` and register the Purifier alias.

```
    'aliases' => [
        // ...
        'Purifier' => HDVinnie\Purifier\Facades\Purifier::class,
    ]
```

Usage
-----

[](#usage)

Use these methods inside your requests or middleware, wherever you need the HTML cleaned up:

```
\clean(Input::get('inputname'));
```

or

```
Purifier::clean(Input::get('inputname'));
```

dynamic config

```
\clean('This is my H1 title', 'titles');
\clean('This is my H1 title', array('Attr.EnableID' => true));
```

or

```
Purifier::clean('This is my H1 title', 'titles');
Purifier::clean('This is my H1 title', array('Attr.EnableID' => true));
```

use [URI filter](http://htmlpurifier.org/docs/enduser-uri-filter.html)

```
Purifier::clean('This is my H1 title', 'titles', function (HTMLPurifier_Config $config) {
    $uri = $config->getDefinition('URI');
    $uri->addFilter(new HTMLPurifier_URIFilter_NameOfFilter(), $config);
});
```

Alternatively, in Laravel 7+, if you're looking to clean your HTML inside your Eloquent models, you can use our custom casts:

```
