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

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

nickbai/sensitive
=================

Filter or replace sensitive words in the text

V1.0.2(3y ago)136MITPHPPHP &gt;=7.0.0

Since Mar 28Pushed 3y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (3)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

```
composer require nickbai/sensitive

```

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

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

Total

2

Last Release

1147d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b331fe002d6a8b54e4e8eba566f86213d3bce2b11c7d317a920fcfe7248e490?d=identicon)[nick-bai](/maintainers/nick-bai)

---

Top Contributors

[![nick-bai](https://avatars.githubusercontent.com/u/16068782?v=4)](https://github.com/nick-bai "nick-bai (6 commits)")

---

Tags

librarysensitive

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[inhere/php-validate

generic data validate, filter library of the php

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

Model mapping, unmapping and validation

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

Json Schema validation for Laravel projects

1036.7k3](/packages/carsdotcom-laravel-json-schema)[erlandmuchasaj/sanitize

A package to sanitize your input.

146.0k](/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)
