cobusbo Posted September 20, 2015 Share Posted September 20, 2015 (edited) Hi I'm trying to create a mute function My Database table layout: ID int AI word varchar 30 I got 260 words in my table now I'm trying to check my $_POST['message'] string to see if any of these words are in the string and if it does it should insert a 10 min mute $resultmute = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $rowmute = mysql_fetch_assoc($resultmute); if (stristr($message,$rowmute['word']) !== false) { $expire = time() + (60 * 10); $querymute = "UPDATE timeban SET user='$name', bantime='$expire', banby='ADMIN' WHERE mxitid='".$mxitid."'"; mysql_query($querymute); } The current problem I have is I want to check case insensitive characters. For instance if I got the word "badwords" in the database and the word is spelled "Badwords" it should still be considered a bad word. At the moment it seems like only certain words in my database get filtered and the rest not... My second question is regarding the replacing of the word with this function function filterBadWords($str) { $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $replacements = "x"; while($row = mysql_fetch_assoc($result1)) { $str = preg_replace('/\b' . $row['word'].'\b/i', ':-x', $str); } return $str; } Is there a way to check if theres another letter next to the word and if so not to filter it. for example assassinate will be filtered to :-x:-xinate but I want to check if there is some character at the end or the beginning of the same word not to filter it... Edited September 20, 2015 by cobusbo Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted September 20, 2015 Solution Share Posted September 20, 2015 The current problem I have is I want to check case insensitive characters. For instance if I got the word "badwords" in the database and the word is spelled "Badwords" it should still be considered a bad word. At the moment it seems like only certain words in my database get filtered and the rest not... Currently your code is only checking for the first word returned by you query. This is because your are not looping over the results of the query. Something like $resultmute = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $bannedWordUsed = false; while($rowmute = mysql_fetch_assoc($resultmute)) { // check if banned word used in message if (preg_match('/\b' . $rowmute['word'] . '\b/i', $message)) { $bannedWordUsed = true; break; // <--- stop looping through the banded words list if a banned word was found } } // if a banned word was found, the set the ban time if($bannedWordUsed) { $expire = time() + (60 * 10); $querymute = "UPDATE timeban SET user='$name', bantime='$expire', banby='ADMIN' WHERE mxitid='".$mxitid."'"; mysql_query($querymute); } Is there a way to check if theres another letter next to the word and if so not to filter it. for example assassinate will be filtered to :-x:-xinate but I want to check if there is some character at the end or the beginning of the same word not to filter it... That should not happen, your regex is using a word boundary \b \b which means it should only be replacing words seperated by whitespace characters. 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.