PHPackages                             doderick/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. doderick/purifier

ActiveThink-extend

doderick/purifier
=================

HTMLPurifier Package for ThinkPHP 5.1

1.0.0(6y ago)08MITPHPPHP &gt;=5.6.0

Since Mar 1Pushed 6y ago1 watchersCompare

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

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

HTMLPurifier Package for ThinkPHP 5.1
=====================================

[](#htmlpurifier-package-for-thinkphp-51)

介绍
--

[](#介绍)

这是 [HTMLPurifier for Laravel](https://github.com/mewebstudio/Purifier) 的移植版本，用于 [ThinkPHP 5.1](https://github.com/top-think/think/tree/5.1)，作用是对 HTML 文本进行过滤，以避免 XSS 攻击。

安装
--

[](#安装)

通过 `composer` 安装

```
composer require doderick/purifier

```

使用
--

[](#使用)

请在应用或者模块目录下定义 `provider.php` 文件，将类库绑定到容器中。

例如：

`application/provider.php` 中进行绑定，

```
return [
    ...
    'purifier' => Doderick\Purifier\Purifier::class,
];
```

配置
--

[](#配置)

安装扩展时，会自动添加默认的配置文件，文件位于 `config/purifier.php` ，如果不存在，可以手动创建，并填入以下内容：

```
return [
    'encoding'      => 'UTF-8',
    'finalize'      => true,
    'cachePath'     => storage_path('app/purifier'),
    'cacheFileMode' => 0755,
    'settings'      => [
        'default' => [
            'HTML.Doctype'             => 'HTML 4.01 Transitional',
            'HTML.Allowed'             => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
            'CSS.AllowedProperties'    => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
            'AutoFormat.AutoParagraph' => true,
            'AutoFormat.RemoveEmpty'   => true,
        ],
        'test'    => [
            'Attr.EnableID' => 'true',
        ],
        "youtube" => [
            "HTML.SafeIframe"      => 'true',
            "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
        ],
        'custom_definition' => [
            'id'  => 'html5-definitions',
            'rev' => 1,
            'debug' => false,
            'elements' => [
                // http://developers.whatwg.org/sections.html
                ['section', 'Block', 'Flow', 'Common'],
                ['nav',     'Block', 'Flow', 'Common'],
                ['article', 'Block', 'Flow', 'Common'],
                ['aside',   'Block', 'Flow', 'Common'],
                ['header',  'Block', 'Flow', 'Common'],
                ['footer',  'Block', 'Flow', 'Common'],

				// Content model actually excludes several tags, not modelled here
                ['address', 'Block', 'Flow', 'Common'],
                ['hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common'],

				// http://developers.whatwg.org/grouping-content.html
                ['figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common'],
                ['figcaption', 'Inline', 'Flow', 'Common'],

				// http://developers.whatwg.org/the-video-element.html#the-video-element
                ['video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
                    'src' => 'URI',
					'type' => 'Text',
					'width' => 'Length',
					'height' => 'Length',
					'poster' => 'URI',
					'preload' => 'Enum#auto,metadata,none',
					'controls' => 'Bool',
                ]],
                ['source', 'Block', 'Flow', 'Common', [
					'src' => 'URI',
					'type' => 'Text',
                ]],

				// http://developers.whatwg.org/text-level-semantics.html
                ['s',    'Inline', 'Inline', 'Common'],
                ['var',  'Inline', 'Inline', 'Common'],
                ['sub',  'Inline', 'Inline', 'Common'],
                ['sup',  'Inline', 'Inline', 'Common'],
                ['mark', 'Inline', 'Inline', 'Common'],
                ['wbr',  'Inline', 'Empty', 'Core'],

				// http://developers.whatwg.org/edits.html
                ['ins', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
                ['del', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
            ],
            'attributes' => [
                ['iframe', 'allowfullscreen', 'Bool'],
                ['table', 'height', 'Text'],
                ['td', 'border', 'Text'],
                ['th', 'border', 'Text'],
                ['tr', 'width', 'Text'],
                ['tr', 'height', 'Text'],
                ['tr', 'border', 'Text'],
            ],
        ],
        'custom_attributes' => [
            ['a', 'target', 'Enum#_blank,_self,_target,_top'],
        ],
        'custom_elements' => [
            ['u', 'Inline', 'Inline', 'Common'],
        ],
    ],

];
```

可以根据项目的需求自定义配置。

例子
--

[](#例子)

可以使用扩展提供的 `clean` 方法对 HTML 文本进行过滤。

使用默认配置

```
clean($request->param('content'));
```

使用动态配置

```
clean($request->param('content'), 'content');
```

参考
--

[](#参考)

[HTMLPurifier for Laravel](https://github.com/mewebstudio/Purifier)

[HTML Purifier 官网](http://htmlpurifier.org/)

License
-------

[](#license)

MIT

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

2269d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2704283c5a5839f3dd03bdf5f874def14392cd1f06b789eb8631cae0f3feee11?d=identicon)[doderick](/maintainers/doderick)

---

Top Contributors

[![doderick](https://avatars.githubusercontent.com/u/40757568?v=4)](https://github.com/doderick "doderick (1 commits)")

### Embed Badge

![Health badge](/badges/doderick-purifier/health.svg)

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[topthink/think-testing

4392.2k8](/packages/topthink-think-testing)

PHPackages © 2026

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