PHP Classes


Recommend this page to a friend!
  Classes of Tadiwanashe Huey Mataruse   PHP Profanity Filter   Download  
Role: Documentation
Content type: text/markdown
Description: Read me
Class: PHP Profanity Filter
Remove profanity words from a given text sentence
Author: By
Last change:
Date: 4 years ago
Size: 1,453 bytes


Class file image Download


A simple to configure PHP Profanity filter, best for chats


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:


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">
    <meta charset="utf-8">
    <form class="" action="#" method="post">
        <input type="text" name="string_pass">
        <input type="submit" name="btnSubmit" value="Profanity Filter">

Censor First word only (if neccessary)

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

* you hot