kamu / aman
Replace badword
Installs: 2 683
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- ext-mbstring: *
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
README
Simple Profanity Filter with Regex
This is a simple project that filters out profane words using regex in PHP. It provides functions to check, filter, and remove unwanted words from a text using regex patterns that account for similar characters.
Features
- Profanity Check: Check if a string contains any unwanted words.
- Profanity Filter: Remove unwanted words from a text.
- Profanity Masking: Replace unwanted words with a masking character, such as
*
.
Installation
To install this package, you can use Composer:
-
Run the following command in your project directory:
composer require kamu/aman
-
Add the list of words you want to filter in the db/lists.php file.
return [ 'badword1', 'badword2', // Add more words you want to filter ];
Usage
You can use the Aman class to filter profanity in your application.
Example Usage
-
Check for Profane Words
use Kamu\Aman; $text = "This is an example with bad words."; $filter = Aman::factory(); if ($filter->check($text)) { echo "This text contains profanity."; } else { echo "This text is clean."; }
-
Mask Profane Words
$text = "This is an example with bad words."; $maskedText = $filter->masking($text, '*'); echo $maskedText; // Output: "This is an example with *** ****."
-
Remove Profane Words
$text = "This is an example with bad words."; $cleanText = $filter->filter($text); echo $cleanText; // Output: "This is an example with ."
-
Get Profane Words from Text
$text = "This is an example with bad words."; $badWords = $filter->words($text); print_r($badWords); // Output: ['bad', 'words']
Contributing
I'm very open to those of you who want to contribute to the Aman!
Security Vulnerabilities
If you find any security vulnerabilities in this Aman, please email DKL via dewanakretarta29@gmail.com.
License
Aman is open-sourced software licensed under the MIT license.