crudleapps/profanity
Composer 安装命令:
composer require crudleapps/profanity
包简介
Profanity filter package for PHP
README 文档
README
It's important to note that, while this was fun to put together, profanity filters will likely never work the way we all need them to. Profanity relies almost entirely on context; for example, "bitch" can easily refer to a female dog. "Dick" could refer to Richard.
However, there are some words that are bad no matter the context. This package tries to remedy the situations where you need to safe guard against naughty words (e.g. in forums where young children frequent)
Installation
There are no other dependencies for this package so run the below and you're good to go.
composer require crudleapps/profanity
Usage
The filter requires at least one Dictionary to function. This package comes with a GB and US dictionary out of the box.
use Crudle\Profanity\Filter; use Crudle\Profanity\Dictionary\GB; $filter = new Filter(new GB); // Clean a string $filter->cleanse('Joe is a little bitch'); // Returns 'Joe is a little *****' // Clean a string with a custom censor character $filter->cleanse('Joe is a little bitch', 'x'); // Returns 'Joe is a little xxxxx' // Check if a string is dirty $filter->isDirty('Joe is a little bitch'); // Returns true
Dictionaries
It is entirely possible that the dictionaries included in this package are either too strict or not strict
enough for your use. That's no problem. You can easily create your own dictionary by extending Crudle\Profanity\Dictionary\AbstractDictionary
All you need to include is a protected $badWords member with your array of words. For example:
class MyDictionary extends AbstractDictionary { protected $badWords = [ 'bollocks', 'twat' ]; } $filter = new Filter(new MyDictionary);
There is another way if you dislike extending someone elses code. You can simply pass your own array of words to any
dictionaries add method.
$dictionary = new GB(); $dictionary->add(['dicks', 'bitches']); // Alternatively, clear the existing words in the dictionary if you want to start fresh $dictionary->clear(); $dictionary->add(['ho', 'testicle']);
crudleapps/profanity 适用场景与选型建议
crudleapps/profanity 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.78k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 crudleapps/profanity 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 crudleapps/profanity 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-22