PHPackages                             shyiran/wordfilter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. shyiran/wordfilter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shyiran/wordfilter
==================

一个屏蔽词检查过滤提取的

1.0.0(3y ago)13191MITPHP

Since Sep 21Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

屏蔽词检测、过滤、提取 （PHP）
=================

[](#屏蔽词检测过滤提取-php)

- 两种实现，TreeWordFilter和ArrayWordFilter，适用于不同的php环境
- TreeWordFilter：适用常驻内存的php环境、swoole、cli
- ArrayWordFilter ： 适用于Web环境，调用一两次就退出程序的。

使用方式
====

[](#使用方式)

```
// 加载你要的单词列表
$keywords = [
    '山羊',
    '草地'
];
if(PHP_SAPI === 'cli'){
    $wordFilter = new \shyiran\wordfilter\TreeWordFilter($keywords);
}else{
    $wordFilter = new \shyiran\wordfilter\ArrayWordFilter($keywords);
}
$content = '那边草地上,有一只山羊';

// '测试是否存在屏蔽词 bool:';
$bool = $wordFilter->test($content);
var_dump($bool);

// 捕获一个屏蔽词 string | null
$word = $wordFilter->matchOne($content);
var_dump($word);
// 捕获所有屏蔽词 array
$words = $wordFilter->matchAll($content);
var_dump($words);
// 给原句中的屏蔽词打上马赛克 string
$newContent = $wordFilter->mosaic($content);
var_dump($newContent);

// 打印结果
bool(true)
string(6) "草地"
array(2) {
  [0]=>
  string(6) "草地"
  [1]=>
  string(6) "山羊"
}
string(23) "那边**上,有一只**"
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

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

1330d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b4cf91c9bbd6aed3eb5d2c2ee1ebaa5e15598056d51b5f5bbdf8f921f51415f?d=identicon)[shyiran](/maintainers/shyiran)

---

Top Contributors

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

---

Tags

words filter

### Embed Badge

![Health badge](/badges/shyiran-wordfilter/health.svg)

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

###  Alternatives

[sarhan/php-flatten

Flattens multidimensional arrays, traversables and vars into one dimensional array.

21177.7k1](/packages/sarhan-php-flatten)[classpreloader/console

Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case

10235.0k5](/packages/classpreloader-console)

PHPackages © 2026

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