chriscloyd Posted June 8, 2007 Share Posted June 8, 2007 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"); } ?> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 8, 2007 Share Posted June 8, 2007 Something like this? <?php $entered = $_POST['message']; $words = array('/badword/','/another/','/words/'); $replay = array('bw','ano','wor'); echo preg_replace($word,$replay,$entered); ?> Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted June 8, 2007 Author Share Posted June 8, 2007 i got this error Warning: preg_replace() [function.preg-replace]: Parameter mismatch, pattern is a string while replacement in an array. in /usr/home/www5965/public_html/jarred/sendchat.php on line 10 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.