PHP code example of devtrope / profanity-filter

1. Go to this page and download the library: Download devtrope/profanity-filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devtrope / profanity-filter example snippets


use ProfanityFilter\ProfanityFilter;

$filter = new ProfanityFilter();

echo $filter->clean('This sh1t is funny'); // This **** is funny

$filter = new ProfanityFilter();

$filter->clean('This shit is funny');        // This **** is funny
$filter->clean('This shit is funny', '#');   // This #### is funny

$filter->containsProfanity('This shit is funny'); // true
$filter->containsProfanity('This is a class');    // false

$matches = $filter->getMatches('This sh1t is funny as fuck');

foreach ($matches as $match) {
    echo "{$match->original} => {$match->profanity} (word #{$match->position})\n";
}

// sh1t => shit (word #1)
// fuck => fuck (word #5)

$filter = new ProfanityFilter('fr');

$filter->clean('Quel connard'); // Quel *******

$filter->addWords('troll');
$filter->addWords(['troll', 'moldu']);

$filter->removeWords('cul');
$filter->removeWords(['cul', 'con']);