PHP code example of pg-momik / no-nepali-profanity

1. Go to this page and download the library: Download pg-momik/no-nepali-profanity 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/ */

    

pg-momik / no-nepali-profanity example snippets


use NoNepaliProfanity\Profanity;

// boolean check — fastest
Profanity::containsProfanity("Great teacher!");        // false
Profanity::containsProfanity("muji");                  // true
Profanity::containsProfanity("मुजीको कक्षा");           // true  (Devanagari + postposition)

// which words — returns normalised matches as they appeared
Profanity::findProfanity("f.u.c.k this sh1t");        // ["fuck", "shit"]
Profanity::findProfanity("f u c k this");              // ["fuck"]
Profanity::findProfanity("Randip Thapa");              // []
Profanity::findProfanity("*ss teacher");               // ["*ss"]

// debugging — see what the matcher actually splits into
Profanity::tokenize("Great teacher!");                 // ["great", "teacher"]

Profanity::censor("you muji");                                   // "you ****"
Profanity::censor("F.U.C.K this Sh1t!");                          // "******* this ****!"
Profanity::censor("you muji", ['mask' => '#']);                    // "you ####"
Profanity::censor("you muji", ['replace' => fn ($m) => '[censored]']);  // "you [censored]"
Profanity::findProfanityMatches("you muji");                      // [ProfanityMatch(text: "muji", normalized: "muji", start: 4, end: 8)]

$result = Profanity::check("you muji");
$result->hasProfanity;   // true
$result->words;          // ["muji"]
$result->censor();       // "you ****"

Profanity::findProfanity("fuck muji मुजी", ['languages' => ['romanized']]);      // ["muji"]
Profanity::containsProfanity("you idiot", ['strictness' => 'lenient']);         // false
Profanity::findProfanity("damn it", ['strictness' => 'strict']);   // ["damn"]

$filter = Profanity::createFilter(['languages' => ['romanized'], 'strictness' => 'lenient']);
$filter->containsProfanity("muji");    // true
$filter->censor("fuck muji");          // "fuck ****"