PHPackages                             isszz/think-sensitive - 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. isszz/think-sensitive

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

isszz/think-sensitive
=====================

thinkphp6+ 敏感词检测，过滤，标记

v0.0.5(2y ago)31131[1 issues](https://github.com/isszz/think-sensitive/issues)MITPHPPHP &gt;=8.0.0

Since Jul 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/isszz/think-sensitive)[ Packagist](https://packagist.org/packages/isszz/think-sensitive)[ RSS](/packages/isszz-think-sensitive/feed)WikiDiscussions main Synced 1mo ago

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

think-sensitive
===============

[](#think-sensitive)

thinkphp6+ 敏感词检测，过滤，标记

 [![Minimum PHP Version](https://camo.githubusercontent.com/e8223ac675b6f9feddec95a806a57528e8009d21035aca7c0650e6006fa81c36/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d3e3d382e302d3838393242462e737667)](https://packagist.org/packages/isszz/think-sensitive) [![Minimum Thinkphp Version](https://camo.githubusercontent.com/2bc52c123b7ec544298bd4aa257f4efb62df5ce49bfa1f6fdfadc2e20cfad61a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7468696e6b7068702d3e3d362e782d3838393242462e737667)](https://packagist.org/packages/isszz/think-sensitive) [![Stable Version](https://camo.githubusercontent.com/fb57e02bb86e772e2f551763f5f1a9afbfeaaae94a821fe39b457b477fdada62/68747470733a2f2f706f7365722e707567782e6f72672f6973737a7a2f7468696e6b2d73656e7369746976652f762f737461626c65)](https://packagist.org/packages/isszz/think-sensitive) [![Total Downloads](https://camo.githubusercontent.com/e9ba24b372305a0e5a3f0265a5c5127b141e8759c641b10f7d402fcbf4a92443/68747470733a2f2f706f7365722e707567782e6f72672f6973737a7a2f7468696e6b2d73656e7369746976652f646f776e6c6f616473)](https://packagist.org/packages/isszz/think-sensitive) [![License](https://camo.githubusercontent.com/b7c46f8aedebd1975065c71ff40f22f400ed7474c62b7a3ed59c2f0fb7aad20e/68747470733a2f2f706f7365722e707567782e6f72672f6973737a7a2f7468696e6b2d73656e7369746976652f6c6963656e7365)](https://packagist.org/packages/isszz/think-sensitive)

安装
--

[](#安装)

```
composer require isszz/think-sensitive
```

配置
--

[](#配置)

```
return [
    // 支持file，array，也可以指向自己敏感词库文件路径
    // file模式时，敏感词库位于tp根目录的config/sensitive/SensitiveWord.txt，也可以指向自定义的词库文件路径
    'mode' => 'file',

    'config' => [
        'repeat' => true, // 重复替换为敏感词相同长度的字符
        'replace_char' => '*', // 替换字符
        // 标记敏感词，标签生成敏感词
        'mark' => 'mark',
    ],

    // 干扰因子
    'interference_factors' => [
        ' ', '&', '*', '/', '|', '@', '.', '^', '~', '$',
    ],

    // 数组模式敏感词
    'sensitive_words' => [
        '工口',
        '里番',
        '性感美女',
    ]
];
```

使用
--

[](#使用)

facade方式

```
use isszz\sensitive\facade\Sensitive;

class Index
{
    public function add()
    {
        // 设置干扰因子
        Sensitive::interferenceFactor(['(', ')', ',', '，', ';', '；', '。']);

        // 添加一个额外的敏感词，words参数支持单敏感词，多词也可以用|分割，或者直接传入多个敏感词数组
        // words = 性感美女|分隔符
        // words = ['性感美女', '数组']
        Sensitive::add(words: '性感美女');

        // 删除的敏感词，words参数同添加的格式一样
        // 第二个参数once为true时，只针对当次: is，replace，mark，操作生效
        Sensitive::remove(words: '性感美女', once: true);
        // 替换
        $replaced = Sensitive::add(words: '垃圾')->replace(content: '替换语句垃圾要被替换', replaceChar: '*', repeat: false);

        // 标记敏感词
        $marked = Sensitive::add(words: '尼玛')->mark(content: '标记的内容，这里尼玛要被标记', tag: 'bad');

        // 提取内容中的所有敏感词
        $badWords = $sensitive->add('狗逼')->get('提取内容中的所有敏感词，狗逼，还有SB都会被提取');

        // 检测
        if (Sensitive::is(content: '检测语句')) {
            return json(['code' => 1, 'msg' => '输入内容包含敏感词，请注意用词。']);
        }

        // 自定义敏感词库
        // 敏感词文件
        Sensitive::custom('SensitiveWord.txt');
        // 数组方式
        Sensitive::custom([
            '垃圾', '尼玛',
            //...
        ])->is('检测尼玛的语句');

        // 添加新敏感词到词库文件
        // append参数为true是追加模式，false时先提取词库，再去重然后合并写入
        $sensitive->addWordToFile(data: '狗逼|傻缺', append: false);
    }
}
```

依赖注入方式

```
class Index
{
    public function add(\isszz\sensitive\Sensitive $sensitive)
    {
        // 设置干扰因子
        $sensitive->interferenceFactor(['(', ')', ',', '，', ';', '；', '。']);
        // ...
    }
}
```

助手函数方式

```
class Index
{
    public function add(Sensitive $sensitive)
    {
        // 设置干扰因子，后返回的Sensitive实例可使用：is，replace，mark
        sensitive_interference_factor(['(', ')', ',', '，', ';', '；', '。'])
            ->is('检测语句尼玛');

        // 添加敏感词，后返回的Sensitive实例可使用：is，replace，mark
        sensitive_add(words: '性感美女')
            ->mark('你是一个性感美女，你说是不是？');

        // 移除敏感词，后返回的Sensitive实例可使用：is，replace，mark
        // 第二个参数once为true时，只针对当次: is，replace，mark，操作生效
        sensitive_remove(words: '工口', once: true)
            ->mark('你这个SB是不是想看工口类的动漫？哈哈！');

        // 检测敏感词
        if (sensitive_is('检测语句尼玛')) {
            return json(['code' => 1, 'msg' => '输入内容包含敏感词，请注意用词。']);
        }

        // replaceChar是用来设置要被替换的敏感词
        // repeat为true时根据检测出的敏感词长度设置replaceChar
        $replaced = sensitive_replace(content: '替换语句垃圾要被替换', replaceChar: '*', repeat: true);
        // tag参数是用来设置包裹敏感词的标签名例如: 这里SB要被标记
        $marked = sensitive_mark(content: '标记的内容，这里SB要被标记', tag: 'bad');

        // 提取内容中的所有敏感词
        $badWords = sensitive_get('谁是SB，谁是狗逼，谁是傻缺');

        // 自定义敏感词库
        // 文件方式
        sensitive_custom('/config/SensitiveWord.txt')
            ->is('检测尼玛的语句');

        // 数组方式
        sensitive_custom([
            '垃圾', '尼玛',
            //...
        ])->is('检测尼玛的语句');

        // 文件词库模式，可以添加新敏感词到词库文件
        // data参数可以是一个数组也可以是用|分割敏感词的字符串
        // append参数为true是追加模式，false时先提取词库，再去重，然后合并写入
        sensitive_add_word_to_file(data: '狗逼|傻缺', append: false);

    }
}
```

使用`request`替换违禁词，当然也可以使用`sensitive_mark`标记

```
// 调用助手类
$content = Request::get('content', '', 'sensitive_replace');
// 使用facade类
$content = Request::get('content', '', 'isszz\sensitive\facade\Sensitive::replace');
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

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 ~6 days

Total

4

Last Release

1005d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/69a944bc69c24c6b069b99b047f791b359844dbc71a42404fbfd6ef3b484c05f?d=identicon)[isszz](/maintainers/isszz)

---

Top Contributors

[![isszz](https://avatars.githubusercontent.com/u/2878463?v=4)](https://github.com/isszz "isszz (11 commits)")

### Embed Badge

![Health badge](/badges/isszz-think-sensitive/health.svg)

```
[![Health](https://phpackages.com/badges/isszz-think-sensitive/health.svg)](https://phpackages.com/packages/isszz-think-sensitive)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)[edward1108/edward-captcha

ThinkPHP6验证码(图片、短信)支持api友好化

157.9k](/packages/edward1108-edward-captcha)

PHPackages © 2026

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