Banned Words filter
This example shows a simple banned words filter , this example opens a text file and if a word in the message is the same as one in the text file this is replaced by ***** . Of course this has drawbacks as innocent words which contain the banned word also get filtered out sadly.
Code
<?php
function censored($message)
{
//the file with the banned words
$fp = fopen("banned.txt","r");
while($word = fgets($fp,10000))
{
//replace words
$message = ereg_replace(trim($word),"******",$message);
}
return $message;
}
?>
<?php
//our phrases
$msg = "This example is a load of shit";
$msg1 = "I like shitake mushrooms";
//display the censored version
echo censored($msg);
echo "<br>";
//this shaws a drawback of this and most other
//bad words filter , if the banned word appears in ANY WORD
//this is filtered meaning innocent words like shitake
echo censored($msg1);
?>
Download
banned.txt
Example
This example is a load of ******
I like ******ake mushrooms