
Laravel 12 Generate QR Code Example...
QR codes have become a widely used method for sharing information quickly and securely. From prod...
In today's digital age, ensuring that user-generated content is appropriate and free from offensive language is a critical concern for developers. Whether you're building a social media platform, a comment section, or a chat application, filtering out profanity is essential to maintain a positive and respectful environment. Enter Profanify, a powerful Laravel package designed to help you easily detect and filter profane language in your applications.
In this blog post, we'll explore what Profanify is, how it works, and how you can integrate it into your Laravel projects.
Profanify is a Laravel package created by Jon Purvis that provides a simple yet effective way to detect and filter profanity in text. It uses a comprehensive list of profane words and phrases to identify inappropriate content, making it easier for developers to enforce community guidelines and maintain a clean user experience.
The package is lightweight, easy to use, and highly customizable, allowing you to tailor it to your specific needs. Whether you want to replace profane words with asterisks, completely block submissions containing profanity, or simply log instances of inappropriate language, Profanify has you covered.
Getting started with Profanify is straightforward. Follow these steps to install and configure the package in your Laravel application:
Run the following command in your terminal to install Profanify:
composer require jonpurvis/profanify
Profanify comes with a configuration file that allows you to customize its behavior. Publish the configuration file using the following command:
php artisan vendor:publish --provider="JonPurvis\Profanify\ProfanifyServiceProvider"
This will create a profanify.php
file in your config
directory.
If you want to add or remove words from the default profanity list, you can do so by editing the profanify.php
configuration file. The words
array contains the list of profane terms that Profanify will detect.
return [
'words' => [
'badword1',
'badword2',
// Add or remove words as needed
],
];
Once installed, you can start using Profanify to filter text in your application. Here are a few examples of how you can use the package:
You can use the Profanify
facade to check and filter a string for profanity:
use JonPurvis\Profanify\Facades\Profanify;
$text = "This is a badword1 example.";
$filteredText = Profanify::filter($text);
echo $filteredText; // Output: "This is a ******** example."
If you simply want to check whether a string contains profanity, you can use the hasProfanity
method:
use JonPurvis\Profanify\Facades\Profanify;
$text = "This is a badword1 example.";
if (Profanify::hasProfanity($text)) {
echo "Profanity detected!";
} else {
echo "No profanity found.";
}
You can customize the replacement text used for profane words by passing a second argument to the filter
method:
use JonPurvis\Profanify\Facades\Profanify;
$text = "This is a badword1 example.";
$filteredText = Profanify::filter($text, '[CENSORED]');
echo $filteredText; // Output: "This is a [CENSORED] example."
Profanify is an excellent tool for developers who want to maintain a professional and respectful environment in their applications. Here are a few reasons why you should consider using it:
Profanify is a valuable addition to any Laravel developer's toolkit, providing an easy and effective way to filter profanity in user-generated content. By integrating this package into your application, you can ensure a cleaner, more respectful environment for your users.
To learn more about Profanify and explore its source code, check out the GitHub repository. If you find the package useful, don't forget to give it a star and contribute to its development!
Have you used Profanify in your projects? Share your experiences and tips in the comments below!
Sophia specializes in creating and maintaining Laravel packages. She has developed numerous popular open-source packages and shares her expertise in extending Laravel functionality through clean, reusable code.
QR codes have become a widely used method for sharing information quickly and securely. From prod...
Introduction
Laravel 12 continues to be a robust, elegant PHP framewor...
If you're aiming to become a Laravel developer or improve your Laravel skills, you're in...
Subscribe to my newsletter to get updated posts