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

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

hashyoo/sensitive-words
=======================

敏感词检测，过滤，文本安全，文本检测

v0.0.6(5y ago)026MITPHPPHP &gt;=5.4.0

Since Sep 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/hashyoo/sensitive-words)[ Packagist](https://packagist.org/packages/hashyoo/sensitive-words)[ RSS](/packages/hashyoo-sensitive-words/feed)WikiDiscussions master Synced 4d ago

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

简单敏感词过滤组件，采用 DFA 算法。
====================

[](#简单敏感词过滤组件采用-dfa-算法)

我们的应用往往要营造良好的交流氛围，或因一些政策上的原因，我们需要限制输出用户的某些输入内容（我们称之为敏感词），但用户的输入是不确定的，一般的我们都会对用户的输入进行二次处理，将一些敏感词进行过滤替换的操作。 如果你也有这方面的需要的话，那这个包可以很方便的实现这一功能。

基本用法
----

[](#基本用法)

### 替换操作

[](#替换操作)

首先你需要构建一个敏感词库，这个包中没有另外提供，你需要根据你自己的需要来创建。你可以选择保存在文件中，也可以存入到数据库中，但最终你需要将它们编成一个数组，类似这样：

```
$sensitive_words = array(
  'SB', '傻逼', 'Fuck'
);
```

然后你就可以像这样简单的使用：

```
use HashyooWordsSafe\Facade\WordsSafe;

$text = 'SB就是傻逼！fuck is a bad word!';

WordsSafe::load($sensitive_words);
$result = WordsSafe::escape($text); // escape 方法会将文本中找到的敏感词使用替代词（默认是*）替换掉。
echo $result; // **就是**！**** is a bad word!

// 你也可以改变默认的替换字符，如换成 'x'。
WordsSafe::setEscapeChar('x');
echo WordsSafe::escape($text); // xx就是xx！xxxx is a bad word!
```

### 检测操作

[](#检测操作)

在某些情况下，我们不需要替换文本中的敏感词，只需要程序检测出是否有敏感词即可。 比如在用户注册时候填写的昵称，为了防止用户冒充官方人员对用户进行诈骗，一般会设置一些不能注册的昵称作为敏感词。 这时我们可以使用 scan 方法，它会返回一个数组，包含所有被检测的到敏感词：

```
use HashyooWordsSafe\Facade\WordsSafe;

$username = $_POST['username'];

$sensitive_words = ['Singiu'];
WordsSafe::load($sensitive_words);
$bad_words = WordsSafe::scan($username);

if (count($bad_words) > 0) {
  echo '昵称中含有不合适的字符！';
}
```

关于性能问题
------

[](#关于性能问题)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

6

Last Release

2017d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1426f942d621addf279b853aca762f7321c8b66b2ce7f532b78adfd225224b31?d=identicon)[wu](/maintainers/wu)

---

Top Contributors

[![Simooonn](https://avatars.githubusercontent.com/u/24266163?v=4)](https://github.com/Simooonn "Simooonn (7 commits)")

---

Tags

phplaravel

### Embed Badge

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

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

###  Alternatives

[galahad/laravel-addressing

Laravel package providing addressing functionality

70316.6k](/packages/galahad-laravel-addressing)[danielebarbaro/laravel-vat-eu-validator

A simple package that validates EU VAT numbers against the central ec.europa.eu database

37369.4k](/packages/danielebarbaro-laravel-vat-eu-validator)[yorcreative/laravel-argonaut-dto

Argonaut is a lightweight Data Transfer Object (DTO) package for Laravel that supports nested casting, recursive serialization, and validation out of the box. Ideal for service layers, APIs, and clean architecture workflows.

1062.8k1](/packages/yorcreative-laravel-argonaut-dto)

PHPackages © 2026

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