Jump to content

mute function


cobusbo
Go to solution Solved by Ch0cu3r,

Recommended Posts

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 by cobusbo
Link to comment
Share on other sites

  • Solution

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.