PHPackages                             pengyu/dfa-filter - 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. [Search &amp; Filtering](/categories/search)
4. /
5. pengyu/dfa-filter

ActiveLibrary[Search &amp; Filtering](/categories/search)

pengyu/dfa-filter
=================

This is a sensitive words filter based on DFA

v1.0.0(6y ago)6342MITPHPPHP &gt;= 5.5.0

Since Oct 31Pushed 5y agoCompare

[ Source](https://github.com/herepy/dfa-filter)[ Packagist](https://packagist.org/packages/pengyu/dfa-filter)[ RSS](/packages/pengyu-dfa-filter/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

简介
--

[](#简介)

一个基于DFA算法的敏感词过滤插件

功能特性
----

[](#功能特性)

- 例用`单利模式`，保持整个项目实例一致
- 导入敏感词文本采用yield生成器`降低内存`
- 支持数组和`文件导入`两种方式添加敏感词，自定义文件导入时的敏感词分割符
- 支持添加`干扰因子`来增强敏感词的识别能力
- 自定义符号`标记`敏感词
- `内置server，适用于api方式调用`
- `匹配模式`模式分为最大最小两种，默认最小匹配模式
- `检测词语`是否是敏感词
- `检测文本`是否包含敏感词
- `过滤文本`中的敏感词
- `单元测试`覆盖率高

使用条件
----

[](#使用条件)

PHP &gt;= 5.5.0

安装说明
----

[](#安装说明)

##### git方式安装:

[](#git方式安装)

```
    git clone https://github.com/herepy/dfa-filter.git
    cd dfa-filter && composer install

```

##### composer方式安装

[](#composer方式安装)

```
    composer require pengyu/dfa-filter

```

##### 引入项目

[](#引入项目)

```
    use Pengyu\DfaFilter\Filter;
    require_once "vendor/autoload.php";
    $filer=Filter::build();
```

如何使用:
-----

[](#如何使用)

##### 初始化实例并设置敏感词库

[](#初始化实例并设置敏感词库)

```
$filter=Filter::build();
$filter->addSensitives(["测试","良好","通过"]);
$filter->importSensitiveFile("words.txt");
```

##### 添加干扰因子

[](#添加干扰因子)

```
$filter->addDisturbance("@");
$filter->addDisturbance(["?","%"]);
```

##### 检查是否是独立的敏感词

[](#检查是否是独立的敏感词)

```
$filter->isKey("测试呀");
$filter->isKey("测试");
$filter->isKey("@测?试");
```

##### 检查是否包含敏感词

[](#检查是否包含敏感词)

```
$filter->check("测试呀");
$filter->check("测试通?过了啊，感觉良?好%");
$filter->check("这次通不过了呀");
```

##### 敏感词替换

[](#敏感词替换)

```
$filter->filter("测试了一下，看看能不能@@通%%过了","^",Filter::DFA_MAX_MATCH);
$filter->filter("简单的内容测?试，有敏感词");
$filter->filter("有很?多测@@试?的词，能?不能良%好?通??%过呢");
```

##### 标记敏感词

[](#标记敏感词)

```
$filter->mark("这里有一个敏感词通过,看看测@试%会不会过");
$filter->mark("这里有一个敏感词通过,看看测@试%会不会过",["",""],Filter::DFA_MAX_MATCH);
```

##### 重置敏感词树和干扰因子

[](#重置敏感词树和干扰因子)

```
$filter->flushSensitives();
$filter->flushDisturbance();
```

##### 查看当前敏感词树和干扰因子

[](#查看当前敏感词树和干扰因子)

```
$filter->getSensitivesTree();
$filter->getDisturbance();
```

##### 启动内置server

[](#启动内置server)

```
php run.php
```

#### 调用server api

[](#调用server-api)

```
curl -H "Content-Type: application/json" -X POST -d '{"action": "isKey", "data":{"word":"敏感词"} }'
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

2434d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1018252?v=4)[Pengyu](/maintainers/Pengyu)[@pengyu](https://github.com/pengyu)

---

Top Contributors

[![herepy](https://avatars.githubusercontent.com/u/16030800?v=4)](https://github.com/herepy "herepy (54 commits)")

---

Tags

filterdfasensitive wordword filter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pengyu-dfa-filter/health.svg)

```
[![Health](https://phpackages.com/badges/pengyu-dfa-filter/health.svg)](https://phpackages.com/packages/pengyu-dfa-filter)
```

###  Alternatives

[clue/stream-filter

A simple and modern approach to stream filtering in PHP

1.7k271.5M8](/packages/clue-stream-filter)[laminas/laminas-filter

Programmatically filter and normalize data and files

9529.5M173](/packages/laminas-laminas-filter)[friendsofcake/search

CakePHP Search plugin using PRG pattern

1712.1M47](/packages/friendsofcake-search)[htmlawed/htmlawed

Official htmLawed PHP library for HTML filtering

411.2M12](/packages/htmlawed-htmlawed)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45864.7k3](/packages/outl1ne-nova-multiselect-filter)[outl1ne/nova-input-filter

An input filter for Laravel Nova

24952.5k](/packages/outl1ne-nova-input-filter)

PHPackages © 2026

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