Results 1 to 9 of 9

Thread: PHP Code Snippet: Naughty Word Filter

  1. #1
    Gimme Fries with that!
    Join Date
    Aug 2004
    Posts
    1,469

    PHP Code Snippet: Naughty Word Filter

    I built a word filter for my website. What it does is basically automatically build links out of celebrity names in my news. Example link http://www.moviesonline.ca/movienews_4634.html You can see all the celeb names are auto-linked. I built the celeb pages so I dont need to tell it what to link to, they follow a pattern so the array is very simple and no work on my part building it.

    I realize this is of next to no value to anyone else but I have dumbed it down a bit and you can use it for simple things like a "bad words" filter. Keep in mind the variables are movie related cause well my CMS is for a movie site :P

    PHP Code:
    <?    
       $cast 
    'Profanity, Profanity2, Profanity3'// Naughty Sailor Talk
       
    $st_str trim($cast' '); // Trim white spaces 
       
    $strs explode(','$cast); // Explode into an array by delimiter
       
    $content 'What the Profanity is going on' //the text to apply it to.
           
       
    for($i=0$i<sizeof($strs); $i++) 
        {           
             
    $str ' '.$strs[$i].' ';
             
    $text eregi_replace($str,' ',$text); 
         } 
    ?>
    The way I use this is $cast is my cast list, and I replace it not with *** but with links to the cast bio. The $content is actually the field where i store the main content of my news in my, MYSQL database. By dumbing it down I have made it so you can easily build a bad word filter. May not be the best way to do it, but it works like a charm on my site.
    Last edited by Emancipator; 06-30-2005 at 08:00 AM.

  2. #2
    Gimme Fries with that!
    Join Date
    Aug 2004
    Posts
    1,469
    I updated the code with 2 changes I had on my site but forgot to share. Both are in the FOR loop. The first one is I added a check to make sure you are not pullling apart words. For example if you have *** in your filter and used the word assimilate the word would have been altered. With the new update it wont be.

    Also str_replace is not a good way to replace words instead I used eregi_replace which is much better since it catches regardless of case.

  3. #3
    žorn in the fast lane piniyini's Avatar
    Join Date
    Aug 2004
    Location
    Dewsbury, UK
    Posts
    53
    Believe it or not I was looking for something like this, so thanks
    [FONT=Fixedsys]my blog @ toseef.com

  4. #4
    Gimme Fries with that!
    Join Date
    Aug 2004
    Posts
    1,469
    let me know if you have any questions about it.. I made it for something else and dumbed it down to just be a profanity filter figuring somebody might use it. I will likely enhance it if anyone has any thoughts on it.

  5. #5
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    That looks pretty cool. I might use it if Google whines at me about how much I swear on my Blog or any of my sites; the potty mouth is a fowl desease which I'm too lazy to cure...

  6. #6
    Registered Member moonshield's Avatar
    Join Date
    Aug 2004
    Location
    Charlotte
    Posts
    1,281
    a fowl disease eh?


    Neat little snippet, I will use it I will.

  7. #7
    Gimme Fries with that!
    Join Date
    Aug 2004
    Posts
    1,469
    always nice to do up a snippet others can use...

  8. #8
    Junior Registered
    Join Date
    May 2009
    Posts
    1

    profanity filter

    I was able to easily integrate the webpurify profanity filter into my php application. I decided to use it when writing my own filter was getting a little to complicated.

  9. #9
    This is great. I built something similar, but with the addition of notifying the webmaster / moderator when swearing occurs (to ban an account, etc.). I think it's funny what you did with the celebrity names though, haha.

Similar Threads

  1. Review: Professional PHP Programming
    By Chris in forum Books
    Replies: 6
    Last Post: 07-17-2013, 05:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •