PHPackages                             guanhui07/dfa-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. guanhui07/dfa-sensitive

ActiveLibrary

guanhui07/dfa-sensitive
=======================

copy from FireLustre/php-dfa-sensitive,To achieve the filtering of sensitive words, based on the determination of finite automata (DFA) algorithm.

2.1.1(1y ago)14MITPHPPHP &gt;=7.2

Since Jan 12Pushed 1y agoCompare

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

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

php-DFA-filterWord
==================

[](#php-dfa-filterword)

### 安装扩展

[](#安装扩展)

```
    composer require guanhui07/dfa-sensitive

```

#### 如果你需要手动引入

[](#如果你需要手动引入)

```
    require './vendor/autoload.php';

    use DfaFilter\SensitiveHelper;
```

### 构建敏感词库树

[](#构建敏感词库树)

场景一: 可以拿到不同（用户）词库数组

```
// 获取感词库索引数组
$wordData = array(
    '察象蚂',
    '拆迁灭',
    '车牌隐',
    '成人电',
    '成人卡通',
    ......
);

// get one helper
$handle = SensitiveHelper::init()->setTree($wordData);
```

场景二: 全站使用一套敏感词库

```
// 获取感词库文件路径
$wordFilePath = 'tests/data/words.txt';

// get one helper
$handle = SensitiveHelper::init()->setTreeByFile($wordFilePath);
```

### 设置干扰因子集合

[](#设置干扰因子集合)

> 注意只干扰因子只支持单个字符或单个汉字，暂不支持词

> 但是多个干扰因子连在一起，敏感词可以准确识别

```
$handle = SensitiveHelper::init()->setStopWordList(['&', '*', '.'])->setTreeByFile($wordFilePath);
```

### 忽略大小写

[](#忽略大小写)

> 注意该设置只有在构建敏感词库树之前调用

> 在构建敏感词库树之后调用，结果可能不符合预期

```
$handle = SensitiveHelper::init()->setIgnoreCase()->setTree(['Av', '赌球网'])
```

### 检测是否含有敏感词

[](#检测是否含有敏感词)

```
$islegal = $handle->islegal($content);
```

### 敏感词过滤

[](#敏感词过滤)

```
// 敏感词替换为*为例（会替换为相同字符长度的*）
$filterContent = $handle->replace($content, '*', true);

// 或敏感词替换为***为例
$filterContent = $handle->replace($content, '***');
```

### 标记敏感词

[](#标记敏感词)

```
$markedContent = $handle->mark($content, '', '');
```

### 获取文字中的敏感词

[](#获取文字中的敏感词)

```
// 获取内容中所有的敏感词
$sensitiveWordGroup = $handle->getBadWord($content);
// 仅且获取一个敏感词
$sensitiveWordGroup = $handle->getBadWord($content, 1);
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

5

Last Release

567d ago

Major Versions

v1.4 → 2.1.12024-10-23

PHP version history (2 changes)v1.1PHP &gt;=5.3

2.1.1PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3abde3fccf025ce86670101d7cfa0641d2415c9daad93e5f0c9573a2b23ddbda?d=identicon)[guanhui07](/maintainers/guanhui07)

---

Top Contributors

[![FireLustre](https://avatars.githubusercontent.com/u/16452711?v=4)](https://github.com/FireLustre "FireLustre (30 commits)")[![jiangwu10057](https://avatars.githubusercontent.com/u/6183367?v=4)](https://github.com/jiangwu10057 "jiangwu10057 (23 commits)")[![guanhui07](https://avatars.githubusercontent.com/u/5820457?v=4)](https://github.com/guanhui07 "guanhui07 (7 commits)")[![zedisdog](https://avatars.githubusercontent.com/u/8280666?v=4)](https://github.com/zedisdog "zedisdog (6 commits)")[![aaronlei](https://avatars.githubusercontent.com/u/16218247?v=4)](https://github.com/aaronlei "aaronlei (1 commits)")[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (1 commits)")[![lbool](https://avatars.githubusercontent.com/u/12405248?v=4)](https://github.com/lbool "lbool (1 commits)")

---

Tags

filterphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/guanhui07-dfa-sensitive/health.svg)

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

PHPackages © 2026

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