Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Blasp

Blasp stats

Downloads
14
Stars
96
Open Issues
0
Forks
4

View on GitHub →

Blasp is a powerful and customisable profanity filter package for Laravel applications

Blasp Icon

GitHub Workflow Status (main) Total Downloads Latest Version License

Blasp - Profanity Filter for Laravel

Blasp is a profanity filter package for Laravel that helps detect and mask profane words in a given sentence. It offers a robust set of features for handling variations of offensive language, including substitutions, obscured characters, and doubled letters.

Installation

You can install the package via Composer:

composer require blaspsoft/blasp

Usage

Basic Usage

To use the profanity filter, simply call the Blasp::check() method with the sentence you want to check for profanity.

use Blaspsoft\Blasp\Facades\Blasp;
 
$sentence = 'This is a fucking shit sentence';
$check = Blasp::check($sentence);

The returned object will contain the following properties:

  • sourceString: The original string you passed.
  • cleanString: The string with profanities masked (e.g., replaced with *).
  • hasProfanity: A boolean indicating whether the string contains profanity.
  • profanitiesCount: The number of profanities found.
  • uniqueProfanitiesFound: An array of unique profanities found in the string.

Example

$sentence = 'This is a fucking shit sentence';
$blasp = Blasp::check($sentence);
 
$blasp->getSourceString(); // "This is a fucking shit sentence"
$blasp->getCleanString(); // "This is a ******* **** sentence"
$blasp->hasProfanity(); // true
$blasp->getProfanitiesCount(); // 2
$blasp->getUniqueProfanitiesFound(); // ['fucking', 'shit']

Profanity Detection Types

Blasp can detect different types of profanities based on variations such as:

  1. Straight match: Direct matches of profane words.
  2. Substitution: Substituted characters (e.g., pro0fán1ty).
  3. Obscured: Profanities with separators (e.g., p-r-o-f-a-n-i-t-y).
  4. Doubled: Repeated letters (e.g., pprrooffaanniittyy).
  5. Combination: Combinations of the above (e.g., pp-rof@n|tty).

Laravel Validation Rule

Blasp also provides a custom Laravel validation rule called blasp_check, which you can use to validate form input for profanity.

Example

$request->merge(['sentence' => 'This is f u c k 1 n g awesome!']);
 
$validated = $request->validate([
'sentence' => ['blasp_check'],
]);
 
// If the sentence contains profanities, validation will fail.

Configuration

Blasp uses a configuration file (config/blasp.php) to manage the list of profanities, separators, and substitutions. You can publish the configuration file using the following Artisan command:

php artisan vendor:publish --tag="blasp-config"

License

Blasp is open-sourced software licensed under the MIT license.


Blaspsoft Blasp Related Articles

Onym - Flexible Filename Generator image

Onym - Flexible Filename Generator

Read article
Token Forge - API Token Management with Laravel Breeze image

Token Forge - API Token Management with Laravel Breeze

Read article
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing