PHPackages                             szwsuny/swfilter - 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. szwsuny/swfilter

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

szwsuny/swfilter
================

Sensitive Word Filtering

1.1.5(7y ago)26MITPHPPHP &gt;=7.0.0

Since Feb 1Pushed 6y agoCompare

[ Source](https://github.com/szwsuny/SwFilter)[ Packagist](https://packagist.org/packages/szwsuny/swfilter)[ RSS](/packages/szwsuny-swfilter/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (5)Used By (0)

SwFilter - 敏感词过滤 - 关键词取出
========================

[](#swfilter---敏感词过滤---关键词取出)

Sensitive Word Filtering
------------------------

[](#sensitive-word-filtering)

这是一个PHP版本的AC自动机，没有啥目的性，就是看到其他语言的实现特别多就做了一个，很简单。 关键词树被缓存在Scope文件夹下，使用前先要建立这个缓存文档。

---

### 依赖

[](#依赖)

```
* PHP >= 7

```

---

### 效率

[](#效率)

在test文件下 add.php 有6000个敏感词汇，你可以直接执行，然后执行 filter.php 平均效率在 0.01秒。(macbook pro i5)

---

### 使用方式

[](#使用方式)

```
* 可以参考test目录
* 过滤/查找 前要先添加关键词缓存。

```

引入项目

```
require __DIR__ . '/../vendor/autoload.php'; //注意调整所在目录位置

use SzwSuny\SW\Filter\SwFilter;

```

声明对象

```
$swFilter = new SwFilter();

```

设定范围

```
$swFilter->setScope('短信类'); //你可以理解为词库的分类，这样你可拥有多个过滤词库，想用哪个用哪个。

```

添加词

```
$swFilter->adds($words); //这个批量添加，$words是个词数组
$swFilter->add($word);   //这个就是一个一个加。

```

保存词库

```
$swFilter->save(); //添加词完事后一定要保存，才可以使用。

```

获得匹配到的词

```
$swFilter->getMatchWords('这个是要匹配的内容或者文章'); //返回匹配到的词数组

```

过滤掉匹配的词

```
$result = $swFilter->filter('这个是要匹配的内容或者文章','*'); //最后这个 * 符号，敏感词将会被替换成它，3个字就是 *** 2个字就是 **

```

### 版本号说明

[](#版本号说明)

```
xx.xx.0 最后一位为0是正式版
xx.xx.1-99 这种属于测试版本

```

---

### 更新

[](#更新)

```
2019年02月1日 1.1.0
    发布正式版本

2019年02月05日 1.1.3
    替换成ac自动机，修复词汇匹配不到的问题,需要重新生成词库。

2019年02月05日 1.1.4
    又修复了一下bug

2019年02月05日 1.1.5
    新增一个函数，解决长词中包含短词的匹配不到问题，正在考虑是否转为正式使用。使用请看overMatch.php

```

sunzhiwei 2019-2-1

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

4

Last Release

2658d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/27332034?v=4)[孙志伟](/maintainers/szwsuny)[@szwsuny](https://github.com/szwsuny)

---

Top Contributors

[![szwsuny](https://avatars.githubusercontent.com/u/27332034?v=4)](https://github.com/szwsuny "szwsuny (9 commits)")

---

Tags

filterfilteringphpsensitive-word-filterphpfilterswfilterSensitive Word Filtering

### Embed Badge

![Health badge](/badges/szwsuny-swfilter/health.svg)

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

PHPackages © 2026

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