PHP filter bad words

php detect swear words
php censor words
profanity filter
bad word filter api
list of swear words for filter
laravel profanity filter
profanity filter api
find bad words in text

I have a filter bad words codes below I want to replace this ARRAY with the .txt file so that I can put all the bad words into the txt file or is there any way to use MYSQL database to store the badwords and then call from there ?

FUNCTION BadWordFilter(&$text, $replace){

 $bads = ARRAY (
      ARRAY("butt","b***"),
      ARRAY("poop","p***"),
      ARRAY("crap","c***")
 );

 IF($replace==1) {                                        //we are replacing
      $remember = $text;

      FOR($i=0;$i<sizeof($bads);$i++) {               //go through each bad word
           $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it
      }

      IF($remember!=$text) RETURN 1;                     //if there are any changes, return 1

 } ELSE {                                                  //we are just checking

      FOR($i=0;$i<sizeof($bads);$i++) {               //go through each bad word
           IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1
      }     
 }
}

$qtitle = BadWordFilter($wordsToFilter,1); 

Yes make a file like bad_words.txt with entries like (note each word combo is on a separate line):

butt,b***
poop,p***
crap,c***

Then read that file into an array like so:

$file_array = file('/path/to/bad_word.txt',FILE_IGNORE_NEW_LINES);

Then to create an array like your $bads array do this:

$bads = array();
foreach ($file_array as $word_combo) {
    $bads[] = explode(',', $word_combo);
}

Hope this helps.

Simple Swear Filter In PHP, Simple Swear Filter In PHP. function filterwords($text){ $filterWords = array('gosh', 'darn', 'poo'); $filterCount = sizeof($filterWords); for($i=0; $i < $filterCount; $i++) { $text = preg_replace('/\b'.$ filterWords[$i]. '\b/ie',"str_repeat('*',strlen('$0'))",$text); } return $text; } You can use something like file_get_contents () to read in from a file, or use a MySQL API to query your database for bad words. Do you have a database schema set up? Also, eregi_replace () is deprecated. Use preg_replace () instead.

I just developed a function that can filter out the bad words

function hate_bad($str)
{
    $bad = array("shit","ass");
    $piece = explode(" ",$str);
    for($i=0; $i < sizeof($bad); $i++)
    {
        for($j=0; $j < sizeof($piece); $j++)
        {
            if($bad[$i] == $piece[$j])
            {
                $piece[$j] = " ***** ";
            }
        }
    }

    return $piece;
}

and call it like this

$str = $_REQUEST['bad']; //'bad' is the name of the text field here
$good = hate_bad($str);   

if(isset($_REQUEST['filter'])) //'filter' is the name of button
{
    for($i=0; $i < sizeof($good); $i++)
    {
        echo $good[$i];
    }
}

jcrowe206/BadWordFilter: A bad word filter for php. Pass in , A bad word filter for php. Pass in a string or multidimensional array to check for the existence of a predefined list of bad words. Use the list that ships with the application or define your own custom blacklist. BadWordFilter only matches whole words (excluding symbols) and not partial words. This is a PHP Class useful if you need to filter (bad, naughty) words from a string (text), whether is a simple string or one containing HTML tags. Here’s the complete source code (we will explain it below): filter.string.class.php

You can do either...

You can use something like file_get_contents() to read in from a file, or use a MySQL API to query your database for bad words.

Do you have a database schema set up? Also, eregi_replace() is deprecated. Use preg_replace() instead.

BanBuilder, The script will take a word or phrase and replace the words from a predefined list of $badwords = $censor->setDictionary('/path/to/my/dictionary.php'); $string  PHP Bad Words. PHP BAD WORDS is a PHP Package that return TRUE or FALSE when it finds a bad word in a text. The cool thing is that you can put rules in each word of the dictionary. Explanation. Alone: If the text is You are a Asshole, and the dictionary has the bad words array( 'ass' ); it doesn't match, because the word ass must be appears alone.

You could use MYSQL.

Just have a table with two columns: the word and the replacement.

Then in your code, you will need to connect to the database and read in each row. But you can then store each row in an array.

The result would be very similar to your current array structure.

To connect to a database, use the tutorial below. http://www.homeandlearn.co.uk/php/php13p1.html

Php bad word filtering - PHP, i created a forumand it's working now but i wanted to have a bad word filtering in posting and replying in my forum with calling badwords in my  This bad word filter class is completly customizable. You may select which words you want to replace and remove one's you don't. You also have an option to replace bad words with a specific filter character. This class is extremely fast for what it does, and it is case-insensative. So parsing large files, such as forum posts is not a problem. Enjoy

Profanity Filter PHP Function (1,700 bad words and profanities , Following is a Profanity Filter PHP Function, which I am currently using to filter bad words from my forum posts. Click here to download my own  Okay, so what the preg_replace_callback does is it compiles a regex pattern consisting of all of the bad words. Matches will then be in the format: /(START OR WORD_BOUNDARY OR WHITE_SPACE)(BAD_WORD)(WORD_BOUNDARY OR WHITE_SPACE OR END)/i The i modifier makes it case insensitive so both bad and Bad would match.

expalmer/php-bad-words, PHP Bad words filtering. Checks for existence of bad word in a string but checks too an alone word or among the string. A bad word filter for php. Pass in a string or multidimensional array to check for the existence of a predefined list of bad words. Use the list that ships with the application or define your own custom blacklist. BadWordFilter only matches whole words (excluding symbols) and not partial words. This will match:

PHP: Swear/Bad Word Filter, A video tutorial showing you how to filter out swear words or bad words that are passed Duration: 18:56 Posted: Dec 21, 2012 The PHP Filter Extension . PHP filters are used to validate and sanitize external input. The PHP filter extension has many of the functions needed for checking user input, and is designed to make data validation easier and quicker. The filter_list() function can be used to list what the PHP filter extension offers:

Comments
  • yes, both txt and db is possible. what's your question? what's the problem?
  • I sense a clbuttic mistake, or in this case, a censored b***erfly in the making
  • This actually doesn't work, you need to use file('/path/to/bad_word.txt', FILE_IGNORE_NEW_LINES); if you want each line to be recognized correctly. Especially if you directly work with strings only.