consoletvs/profanity 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

consoletvs/profanity

Composer 安装命令:

composer require consoletvs/profanity

包简介

PHP library to block bad words in a string

README 文档

README

Profanity

StyleCI Status Build For PHP Total Downloads Latest Stable Version License

What is Profanity?

Profanity is a PHP library that allows blocking bad words out of a given string. It currently blocks more than 2.555 words in different languages. It's very easy to use and can filter a 100 chars string in about 0.0021 seconds!

Sample Filter

This example is a simple string that is going to be filtered using this library.

$clean_words = Profanity::blocker('My cool string bitch')->filter()

// My cool string *****

Documentation

Installation

First, require it using composer:

composer require consoletvs/profanity

Laravel

To install it on laravel, simply add the service provider and the alias in config/app.php:

Service Provider:

ConsoleTVs\Profanity\ProfanityServiceProvider::class,

Alias (optional):

'Profanity' => ConsoleTVs\Profanity\Facades\Profanity::class,

Usage

PHP

$words = 'My bad word bitch';
$clean_words = \ConsoleTVs\Profanity\Builder::blocker($words)->filter();
// My bad word *****

// Filter words only by English and German bad words.
$clean_words = \ConsoleTVs\Profanity\Builder::blocker($words, languages: ['en', 'de'])->filter();

Laravel

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use ConsoleTVs\Profanity\Facades\Profanity;
// or using the alias:
// use Profanity;

class HomeController extends Controller
{
    /**
     * Simple test function.
     *
     * @return string
     */
    public function test()
    {
        $words = 'My bad word bitch';

        return Profanity::blocker($words)->filter();
        // My bad word *****
    }
}

Methods

Constructor

  • blocker($text, $blocker = '****', $languages = [])

    Setup the text and the blocker to use.

    note: The blocker defaults to ****

    note: Pass language codes to reduce the list of bad words that are taken into account.

Class Methods

  • strict(true/false)

    Set the strict mode to enabled or disabled. Strict mode replaces the string even if it's not a word: assets => (tagged as ass) => **** Disable to ensure normal usage. Defaults to false.

  • strictClean(true/false)

    Set the strict clean mode to enabled or disabled. Strict clean mode ensures the first blocked character is repeated for each bad word character. If so, a bad word of length = 3 (ass) will result in a ***, instead of the blocker (defaults to ****). If the blocker is -**- then the same example as above would produce --- as strict clean true and -**- as false. Defaults to true.

  • clean()

    Returns true if the text have no bad words on it.

  • filter()

    Filters the text with the given blocker.

  • badWords()

    Return the bad words found in the text.

  • text($text)

    Sets the text to filter.

  • blocker($blocker)

    Sets the string that will replace the bad words.

  • dictionary($dictionary)

    Sets the dictionary. If string is provided, it will be treated as a path and will try to decode the json contained in the path. If array is provided, it will set the dictionary.

    Example dictionary:

    [
        {
            "language": "en",
            "word": "bitch"
        },
        {
            "language": "en",
            "word": "fuck"
        }
    ]

License

MIT License

Copyright (c) 2017 Erik Campobadal

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.

consoletvs/profanity 适用场景与选型建议

consoletvs/profanity 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.12M 次下载、GitHub Stars 达 123, 最近一次更新时间为 2017 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 consoletvs/profanity 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 consoletvs/profanity 我们能提供哪些服务?
定制开发 / 二次开发

基于 consoletvs/profanity 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.12M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 123
  • 点击次数: 27
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 123
  • Watchers: 3
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-28