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

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

anxu/sensitive
==============

Filter or replace sensitive words in the text

v1.0.0(7y ago)0721MITPHPPHP &gt;=7.0.0CI failing

Since Jun 11Pushed 7y agoCompare

[ Source](https://github.com/anxu1212/sensitive)[ Packagist](https://packagist.org/packages/anxu/sensitive)[ RSS](/packages/anxu-sensitive/feed)WikiDiscussions master Synced 3w ago

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

Sensitive word
==============

[](#sensitive-word)

基于DFA算法，实现敏感词的判断 和 过滤

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist anxu/sensitive "*"

```

or add

```
"anxu/sensitive": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

1.将敏感词转为二维节点数组

```
$words=[
    '苹果',
    '香蕉'
];
$nodes =  Utils::words2Node($words);

//[
//    [
//        Node('苹', false),
//        Node('果', true)
//    ],
//    [
//        Node('香', false),
//        Node('蕉', true)
//    ],
//]
```

2.构建字典树

```
$tree = new Tree($nodes);
// $tree = new Tree();
// $tree->appendMultiple($nodes)
```

3.创建敏感词处理类，处理文本

```
$sensitive = new SensitiveWords($tree);
//$sensitive = new SensitiveWords();
//$sensitive->setTree($tree);

$text = '苹果正好吃，我不爱吃香蕉, 香梨才是王道，香水有毒';
//如果文本包含敏感词，则返回包含的敏感词数组；否则返回false
$res = $sensitive->has($text);

//用指定字符，替换文本中敏感词
$string = $sensitive->filter($text,'#');
```

### 例子

[](#例子)

```
//敏感词数组;
$words=['苹果','香蕉'];

$nodes =  Utils::words2Node($words);
$tree = new Tree($nodes);
//如果敏感词数量比较大，字典树构建会比较慢，建议将构建好的字典树进行缓存
$sensitive = new SensitiveWords($tree);

$text = '苹果正好吃，我不爱吃香蕉, 香梨才是王道，香水有毒';
$res = $sensitive->has($text);
$string = $sensitive->filter($text,'#');
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

2570d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5273409?v=4)[Vu Pham](/maintainers/anxu)[@Anxu](https://github.com/Anxu)

---

Top Contributors

[![anxu1212](https://avatars.githubusercontent.com/u/13920119?v=4)](https://github.com/anxu1212 "anxu1212 (2 commits)")

---

Tags

librarysensitive

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[inhere/php-validate

generic data validate, filter library of the php

26089.0k13](/packages/inhere-php-validate)[runz0rd/mapper-php

Model mapping, unmapping and validation

17467.8k2](/packages/runz0rd-mapper-php)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1040.9k5](/packages/carsdotcom-laravel-json-schema)[erlandmuchasaj/sanitize

A package to sanitize your input.

146.6k](/packages/erlandmuchasaj-sanitize)[rodrigojavornik/php-cleanup

A PHP Sanitation Library

121.6k](/packages/rodrigojavornik-php-cleanup)

PHPackages © 2026

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