Page 1 of 1
How to filter offensive content?
Posted: Sat Feb 08, 2003 12:52 am
by senthil
Hi:
I want to restrict the users of my site from posting offensive messages. Is there anyway to do this? The only thing that I can think of is, store a list of possible foul words and when a message is posted, check if any of those words are present. But I would like to know is there any better way of doin it.
Thank you
Senthil
Hello
Posted: Sat Feb 08, 2003 3:35 am
by crazyjimsmith
I am not an expert or anything but I have seen it done the way you mentioned and I frankly cant think of any other way of doing it.
Posted: Sat Feb 08, 2003 10:26 am
by oldtimer
That is how I do it. I have a database table with words to filter. then on the page that the post submission goes to it convertes everything to lower case letters, breaks it apart to word by word and then checks each word to see if it is in the DB. If it is then they get a message saying what word was found and that it is not allowed and then they need to go back and change it. I could replace the word but figured I would make them
Here is a part of code that I use. Crude I know but it works for me.
Code: Select all
<?php
if(strlen($content) > 1000) {
echo "Sorry but your ad is more than 1000 characters. Please go back and try again.";
exit;
}
else {
// start of filter for banned words
$db_conn = mysql_connect("localhost", "$DBuser", "$DBpass");
mysql_select_db("$DBname");
$words = strtolower($contents);// convert to lower case letters
$words = preg_replace("/\s+/", " ", $words);// gets rid of extra white spaces
$words=explode(" ",$words);
for($i=0;$i<count($words);$i++){
$test=($words[$i]);
$sqlquery = "SELECT * From bannedwords where cuss='$test'";
$result2 = mysql_query($sqlquery);
if (mysql_num_rows($result2) >0 )
{
$heading="Banned Word Detected";
include("../wideth.php");
echo "<BR>";
echo "We are sorry but $test is a banned word. Please go back and remove it.";
exit;
} else {
if (strstr($str,$words[$i]) && $words[$i]!="")
print $words[$i]." is into the string!";
}
} // end of filter for banned words
?>
Posted: Sat Feb 08, 2003 1:26 pm
by virgil
Hi
Just thought I'd throw another way at you...same principle though...
this replaces the word, but I like Oldtimers idea of making them change it too.
$badwords = array(' badword1 ',' bad2word ','etc...');
$text1 = strtolower($text1);
$text1 = str_replace($badwords, '%*$#@!',$text1);
$count=substr_count($text1,'%*$#@!');
//for multiple fields
if($count>0){
$count_total=$count_total+$count;
}
//a neat little script I picked up somewhere that closes the initial browser window,
rudely kicking them off the site without explanation.
if($count_total >3 ){echo "<OBJECT ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></OBJECT>
<SCRIPT>WB.ExecWB(45,2);</SCRIPT>"."111111111";}
Hope it helps
