shebbycs Posted December 10, 2011 Share Posted December 10, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/ Share on other sites More sharing options...
freelance84 Posted December 10, 2011 Share Posted December 10, 2011 A simple str_replace can fix this: $test = 's h i t '; $test = str_replace(' ','',$test); echo $test; Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296519 Share on other sites More sharing options...
shebbycs Posted December 10, 2011 Author Share Posted December 10, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296528 Share on other sites More sharing options...
QuickOldCar Posted December 10, 2011 Share Posted December 10, 2011 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() Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296529 Share on other sites More sharing options...
freelance84 Posted December 10, 2011 Share Posted December 10, 2011 What he said ^^^ Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296530 Share on other sites More sharing options...
shebbycs Posted December 10, 2011 Author Share Posted December 10, 2011 What he said ^^^ hahaha im will ask quickold car but thanks for the help really appreciated Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296548 Share on other sites More sharing options...
shebbycs Posted December 10, 2011 Author Share Posted December 10, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296550 Share on other sites More sharing options...
QuickOldCar Posted December 10, 2011 Share Posted December 10, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296554 Share on other sites More sharing options...
shebbycs Posted December 10, 2011 Author Share Posted December 10, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296556 Share on other sites More sharing options...
QuickOldCar Posted December 10, 2011 Share Posted December 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1296561 Share on other sites More sharing options...
shebbycs Posted December 20, 2011 Author Share Posted December 20, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252880-chat-filtering-abuse-word-space-problem/#findComment-1299782 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.