ConsoleTVs / Profanity

PHP library to block bad words in a string
MIT License
104 stars 45 forks source link

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

Class Methods

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.