Jump to content

php filter


chriscloyd

Recommended Posts

I made a chat room with php and now im trying to make a bad word filter cna someone help me? not to code but to lead me in the right direction heres the script i have now thats not working

<?php
session_start();
mysql_connect('localhost','******','*****');
mysql_select_db('*****');
function filterBadWords($str){

// words to filter
$badwords=array( "fuck", "bitch", "ass", "a s s", "f u c k", "cunt", "pussy");

// replace filtered words with
$replacements=array( "&#()*@", "@^%(*!", "*&@&^@&@#" );

for($i=0;$i < sizeof($badwords);$i++){
  srand((double)microtime()*1000000); 
  $rand_key = (rand()%sizeof($replacements));
  $str=eregi_replace($badwords[$i], $replacements[$rand_key], $str);
}
return $str;
}
if (isset($_SESSION['thewayofthejew'])) {
$time = date('n/j/y g:i:s A');
$message = strip_tags($_POST['message']);
filterBadWords($message);
mysql_query("INSERT INTO chat (`user`, `message`, `time`) VALUES ('".$_SESSION['thewayofthejew']."', '".$str."', '".$time."')");
header("Location: index.php?page=chat");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/54688-php-filter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.