定制 crudleapps/profanity 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

crudleapps/profanity

最新稳定版本:v1.0.1

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']);

统计信息

  • 总下载量: 1.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-22