PHP Classes

PHP Profanity Filter: Remove profanity words from a given text sentence

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 171 This week: 1All time: 8,820 This week: 560Up
Version License PHP version Categories
profanus 1.0.0The PHP License5PHP 5, Text processing, Content manag...
Description 

Author

This class can remove profanity words from a given text sentence.

It takes a text sentence and checks if it contains words that are considered to be profane that is read from a text file.

The class can find and censor profane words in a whole sentence or just the first word replacing them by * characters.

Picture of Tadiwanashe Huey Mataruse
  Performance   Level  
Name: Tadiwanashe Huey ... <contact>
Classes: 1 package by
Country: Zimbabwe Zimbabwe
Age: 34
All time rank: 42292 in Zimbabwe Zimbabwe
Week rank: 411 Up1 in Zimbabwe Zimbabwe Up

Example

<?php
require "Profanus.php";
$clean = new Profanus();

if (isset(
$_POST['btnSubmit'])) {

 
$sentence = $_POST['string_pass'];
 
// $censored = $clean->censor_first_word($sentence);
 
$censored = $clean->censor($sentence);
  echo
$censored;

}

?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <form class="" action="#" method="post">
        <input type="text" name="string_pass">
        <input type="submit" name="btnSubmit" value="Check">
    </form>
  </body>
</html>


Details

Profanus

A simple to configure PHP Profanity filter, best for chats

Configuration:

You must start by populating the bad words array either direct in the code OR make a simple list inside the blacklist.txt When populating the text file, the most important rule is: - each bad word must be on a new line - bad words be listed in small caps

The text file has some sample bad words, just follow along with the structure. To use the class in your code, simply follow the steps below (you can clone or download the package):

require "Profanus.php";

$sentence = "The sexy ass bitch";
$clean = new Profanus();
$censored = $clean->censor($sentence);

echo $censored;

Simple example with form:

<?php

require "Profanus.php";

if (isset($_POST['btnSubmit'])) {

  $sentence = $_POST['string_pass'];
  $clean = new Profanus();
  $censored = $clean->censor($sentence);
  echo $censored;

}

?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <form class="" action="#" method="post">
        <input type="text" name="string_pass">
        <input type="submit" name="btnSubmit" value="Profanity Filter">
    </form>
  </body>
</html>

Censor First word only (if neccessary)

$sentence = "Bitch you hot";
$clean = new Profanus();
$censored = $clean->censor_first_word($sentence);
echo $censored;
Output:

* you hot

:v:


  Files folder image Files  
File Role Description
Accessible without login Plain text file blacklist.txt Data Documentation
Accessible without login Plain text file example.php Example Example script
Plain text file Profanus.php Class Class source
Accessible without login Plain text file README.md Doc. Read me

 Version Control Unique User Downloads Download Rankings  
 100%
Total:171
This week:1
All time:8,820
This week:560Up
User Comments (1)