Jump to content

Recommended Posts

chatlog.php

 

function filterBadWords($str)
{
    $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); 
    $replacements = "*";
    
    while($row = mysql_fetch_assoc($result))
    {
          $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str);
    }  
    
    return $str;
}

 

I am has two question

 

1. Is this just a function only or did it used any technique method like keyword comparison or any other technique

 

2. For example when its banned this badword for example suck it can be banned according to ****  but when s u c k it does not banned it im means when it is white space although the same word the function does not banned it any modification?

Link to comment
https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/
Share on other sites

 

A simple str_replace can fix this:

 

$test = 's h i t ';
$test = str_replace(' ','',$test);
echo $test;

 

 

but im don want to declare it as im had put all the badword in database im want only the root words for example suck it can also filter the s u c k also :) and by the way can you answer my first question :) thanks you

I think because this is a group of words in a chat message, the str_replace will not work because it will clump the words together.

 

Look over what I did here, and can do it similar to your needs with a while loop for results, versus the array list and loop I did.

 

<?php
function filterBadWords($str) {
    
    $replacements = "*";
    $bad_words_array = array("chit","poop","shat","chits");
    
    foreach($bad_words_array as $bad_words) {
    $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words);
    $spaced_bad_words = trim($spaced_bad_words);
    
          $str = preg_replace("/$bad_words|$spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str);
    }  
    
    return $str;
}

$text = "I have to deal with a whole pile of chit dealing with you. Even C H I T will work too.";
echo filterBadWords($text);
?>

 

results:

I have to deal with a whole pile of **** dealing with you. Even **** will work too.

 

The above words will now look for bad words case-insensitive as well.

 

eregi_replace is deprecated and should use preg_replace()

I think because this is a group of words in a chat message, the str_replace will not work because it will clump the words together.

 

Look over what I did here, and can do it similar to your needs with a while loop for results, versus the array list and loop I did.

 

<?php
function filterBadWords($str) {
    
    $replacements = "*";
    $bad_words_array = array("chit","poop","shat","chits");
    
    foreach($bad_words_array as $bad_words) {
    $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words);
    $spaced_bad_words = trim($spaced_bad_words);
    
          $str = preg_replace("/$bad_words|$spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str);
    }  
    
    return $str;
}

$text = "I have to deal with a whole pile of chit dealing with you. Even C H I T will work too.";
echo filterBadWords($text);
?>

 

results:

I have to deal with a whole pile of **** dealing with you. Even **** will work too.

 

The above words will now look for bad words case-insensitive as well.

 

eregi_replace is deprecated and should use preg_replace()

 

 

thanks for showing the code but is this function only an function or an any element technique was used for this function?

I don't fully understand your question.

 

This function is named and created, is not a standard php function, it's custom.

 

The function itself can be used in any way you see fit to use it.

 

It could be modified upon more.

 

To sum the purpose of this function up:

The function takes a string of words, cycles through all the badwords, and for the ones that match.... replaces each letter of the word with a * and returns the modified string

I don't fully understand your question.

 

This function is named and created, is not a standard php function, it's custom.

 

The function itself can be used in any way you see fit to use it.

 

It could be modified upon more.

 

To sum the purpose of this function up:

The function takes a string of words, cycles through all the badwords, and for the ones that match.... replaces each letter of the word with a * and returns the modified string

 

 

im know you could not get my question actually my main question is for example some of them using as ANN,or fuzz logic as the technique so back to my same question is this function using techique im means the key word :) but if you don understand its ok because you had solved one of my problem thanks :)

There is no advanced logic in this function. Such as ai,similar words, similar meanings or anything like that.

 

it simply takes a bad word and if the word exists in the string it will perform the action on that word.

 

but due to the few modifications it can now also do uppercase/lowercase/mixed case, as well as bad words that have a prefix or suffix.

 

  • 2 weeks later...

I think because this is a group of words in a chat message, the str_replace will not work because it will clump the words together.

 

Look over what I did here, and can do it similar to your needs with a while loop for results, versus the array list and loop I did.

 

<?php
function filterBadWords($str) {
    
    $replacements = "*";
    $bad_words_array = array("chit","poop","shat","chits");
    
    foreach($bad_words_array as $bad_words) {
    $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words);
    $spaced_bad_words = trim($spaced_bad_words);
    
          $str = preg_replace("/$bad_words|$spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str);
    }  
    
    return $str;
}

$text = "I have to deal with a whole pile of chit dealing with you. Even C H I T will work too.";
echo filterBadWords($text);
?>

 

results:

I have to deal with a whole pile of **** dealing with you. Even **** will work too.

 

The above words will now look for bad words case-insensitive as well.

 

eregi_replace is deprecated and should use preg_replace()

 

 

FILTER BAD WORDS FUNCTION

function filterBadWords($str)
{
    $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); 
    $replacements = "*";
    
    while($row = mysql_fetch_assoc($result))
    {     
          $badwords= $row['badwords'];
          $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $badwords);
          $spaced_bad_words = trim($spaced_bad_words);
          $str = preg_replace("/$badwords|$spaced_bad_words/i", str_repeat('*', strlen($badwords)), $str);
    }
    
    return $str;
}

 

I got this error

 

"Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1"

 

 

Which code i wrong?

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.