Results 1 to 6 of 6

Thread: Bad Word Filter and Calling in Code (again ;))

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    England
    Posts
    312

    Bad Word Filter and Calling in Code (again ;))

    Hiya

    Im currently working on building a forum, and I have ran into a few difficulties, well, maybe not, "difficulties" as such, but troubleing events!

    The first, is my bad word filter, the only way I can think of doing this, is by putting each individual word in the post into an array, thats easy enough, and then putting every "banned" word into another array. It would then run a loop which compared the two and if it found a bad word it would change it. However this seems like itll be alot of hard work for the forum as its checking like, 10 words, against every 1 word in the post!

    Im having a little trouble with my LINK call
    Code:
    <link rel="script" type="php" href="page-stats.php">
    can anyone help me as of where i went wrong? I did put ths in the head btw!
    Last edited by JafferAB; Dec 21st, 2002 at 06:15 AM.
    Power to 2000 Electronic Donkeys!
    www.edonkey2000.com
    I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You wouldn't have to loop through every word in the post. You could use preg_replace() to replace every occurance of each banend word. So if you had to words, you'd just have to loop through each one of them.

    Do a search of these forums on preg_replace() to see some good examples that have been posted.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    A quick note: why preg_replace() instead of str_replace()?

    preg_replace() will allow you to use expressions to do smart replaces. Say you want to replace the word 'ass'

    Using str_replace(), it will also replace 'glass', 'grass', 'mass', etc. preg_replace will allow you to see if it's a single word, and replace things like 'dumb-ass, ass!, ass? ass, etc. For str_replace() you would need to do each one of those individually.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: Bad Word Filter and Calling in Code (again ;))

    Originally posted by JafferAB
    Im having a little trouble with my LINK call
    Code:
    <link rel="script" type="php" href="page-stats.php">
    can anyone help me as of where i went wrong? I did put ths in the head btw!
    that is invalid and you can't do it that way. you have to use php's include

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    England
    Posts
    312
    Originally posted by The Hobo
    You wouldn't have to loop through every word in the post. You could use preg_replace() to replace every occurance of each banend word. So if you had to words, you'd just have to loop through each one of them.

    Do a search of these forums on preg_replace() to see some good examples that have been posted.
    yeah, i knwo that, but it would still mean splitting up every word into an array and then use the array of bad words to search through very bit of the variable.


    that is invalid and you can't do it that way. you have to use php's include
    just did a quick look in my book, and seems like this include() statement is pretty cool

    cheers!
    Power to 2000 Electronic Donkeys!
    www.edonkey2000.com
    I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by JafferAB
    yeah, i knwo that, but it would still mean splitting up every word into an array and then use the array of bad words to search through very bit of the variable.
    What...?

    Code:
    'if storing words in a database:
    function cusswords($text) {
        //connect to database
            
        $results = mysql_query("SELECT * FROM CussWords");
        if ($result = mysql_fetch_array($results)) {
            do {
                $text = preg_replace("/([\:-\@]|[\[-\`]|[\!-\/]|\s|^)" . preg_quote($result['word']) . "(\s|$|[\:-\@]|[\!-\/]|[\[-\`])/isu","\\1" . $result['rep'] . "\\2", $text);
            } while ($result = mysql_fetch_array($results));
        }
            
        return $text;
    }
    
    
    'if storing words in an array:
    function cusswords($text) {        
        $words[] = array("dog", "cat", "fish");
        $rep[] = array("***", "***", "***");
            
        for ($i = 0; $i < count($words); $i++) {
            $text = preg_replace("/([\:-\@]|[\[-\`]|[\!-\/]|\s|^)" . preg_quote($words[$i]) . "(\s|$|[\:-\@]|[\!-\/]|[\[-\`])/isu","\\1" . $rep[$i] . "\\2", $text);
        }
            
        return $text;
    }
    It's that easy. Execution only takes a few seconds. This is the best way to do it. I still don't understand what your problem is.
    Last edited by The Hobo; Dec 23rd, 2002 at 04:50 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width