2 Star 13 Fork 2

nop / wordfilter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

屏蔽词检测、过滤、提取 (PHP)

  • 两种实现,TreeWordFilter和ArrayWordFilter,适用于不同的php环境

  • TreeWordFilter:适用常驻内存的php环境、swoole、cli

  • ArrayWordFilter : 适用于Web环境,调用一两次就退出程序的。

安装

composer require wuxue107/wordfilter

使用方式

// 加载你要的单词列表
$keywords = [
    '山羊',
    '草地'
];
if(PHP_SAPI === 'cli'){
    $wordFilter = new \wuxue107\wordfilter\TreeWordFilter($keywords);
}else{
    $wordFilter = new \wuxue107\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) "那边**上,有一只**"
MIT License Copyright (c) 2021 wuxue107 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

屏蔽词,敏感词,黑词 过滤、查找、打马赛克 展开 收起
PHP
MIT
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/wuxue107/wordfilter.git
git@gitee.com:wuxue107/wordfilter.git
wuxue107
wordfilter
wordfilter
master

搜索帮助