Current location: Hot Scripts Forums » Programming Languages » PHP » Bad word filter function


Bad word filter function

Reply
  #1 (permalink)  
Old 11-21-06, 02:38 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Bad word filter function

I have the following function to filter bad words:

PHP Code:

function filterBadWords($str)

{
    
$badwords = array("dog");
    
$replacements "*";
    
    for(
$i=0$i count($badwords); $i++)
    {
        
$str eregi_replace($badwords[$i], $replacements$str);
    }
    
    return 
$str;

I call the function with :

PHP Code:

print filterBadWords("dogma"); 

And php show the following output :

Code:
*ma
I need to see this output :

Code:
***ma
"dog" has 3 charachter. I need to show 3 asterisk.. If another bad word has 7 charachters, an example: "bastarduser" and I filter "bastard" I need to see :
7 asterisk.

What I need to do to solve this problem ?

Thanks !
Reply With Quote
  #2 (permalink)  
Old 11-21-06, 02:43 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:



foreach ($badwords AS $badword)
{
    
eregi_replace($badwordstr_repeat('*'strlen($badword)), $str);

Reply With Quote
  #3 (permalink)  
Old 11-21-06, 02:51 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks nico, I appreciate your help !

PHP Code:

function filterBadWords($str)

{
    
$badwords = array("dog");
    
$replacements "*";
    
    foreach (
$badwords AS $badword)
    {
          
$str eregi_replace($badwordstr_repeat('*'strlen($badword)), $str);
    }  
    
    return 
$str;

I have the last question.

Now I filter word "dog" and I have the following word : "dogish" the filtered result is "***ish"

Ok, I want to add an extra option, more accurate filtering. When I filter the word "{dog}" instead of "dog" I want to see "***" and "dogish" appear without filtering.

Exist a way to do this ?
Reply With Quote
  #4 (permalink)  
Old 11-21-06, 03:51 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I need something like Vbulletin forum word filtering :

Code:
Type all words you want censored in the field below. Do not use commas to separate words, just use spaces. For example, type "dog cat boy", rather than "dog, cat, boy."

If you type "dog", all words containing the string "dog" would be censored (dogma, for instance, would appear as "***ma"). To censor more accurately, you can require that censors occur only for exact words. You can do this by placing a censor word in curly braces, as in {dog}. Signifying "dog" in the curly braces would mean that dogma would appear as dogma, but dog would appear as "***". Thus your censor list may appear as: cat {dog} {barn} barn

Do not use quotation marks and make sure you use curly braces, not parentheses, when specifying exact words.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Filter in PHP seanknighton Script Requests 0 10-31-05 06:44 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 05:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.