GFXVoid Graphic Design Forum

Remove Text Formatting
Loading...

» Online Users: 8,008

0 members and 8,008 guests
No Members online

» Site Navigation

 > FAQ

» Stats

Members: 35,442
Threads: 103,075
Posts: 826,688
Top Poster: cc.RadillacVIII (7,429)
Welcome to our newest member, Lekelindids
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Badword Filter

  1. #1
    Join Date
    Dec 2004
    Location
    Buffalo Grove, Illinois
    Posts
    350

    Default

    A simple PHP tutorial which blocks out whatever word that you would like it to block out.

    text.htm
    Code:
    <html>
    <head>
    <title>Simple Badword Filter</title>
    </head>
    <body>
    <font face='verdana' size='2'>
    <h1>Simple Badword Filter</h1>
    <form method='post' action='testit.php'>
    <textarea name='text' rows='10' cols='20'></textarea>
    <input type='submit' value='Test It'>
    </form>
    </font>
    </body>
    </html>
    testit.php
    Code:
    <?php
    /* Check.php */
    
    function check() /* Establishes the function check */
    {
    global $text; /* Gets All Variables */
    
    //To Add New Words, Just Copy One Line From Below And Paste It Below The Third Line. Just Replace the first word in quotes with the word you would like, and the second word in quotes to what you would like to change it to.//
    
    $text = str_replace("hey","****",$text); /* Replaces the word "hey" into "****" */
    $text = str_replace("pie","****",$text);
    $text = str_replace("php","***",$text);
    
    echo $text;
    
    }
    
    return check(); /* Returns the function check() */
    
    ?>
    Example Here

    Brought To You By PHPMini

  2. #2
    Join Date
    Dec 2004
    Location
    GFXVoid
    Posts
    4,412

    Default

    That could be very useful for renaming mistypings and such, thanks for your tutorial!

  3. #3
    Join Date
    Mar 2005
    Location
    Stockholm, Sweden
    Posts
    156

    Default

    I would code it differently, since replacing each word seperately will be slower than my code here.. (Actually i would use mysql, but i can't be bothered here)

    Code:
    <?php
    
    function check($string)
    {
    $replace = array();
    $with = array();
    
    $replace[] = "hey";
    $with[] = "***";
    
    $replace[] = "test";
    $with[] = "monkey";
    
    /* just keep adding em */
    
    return str_replace($replace, $with, $string);
    }
    echo check("hey, i'm testing"); /* will return ***, i'm monkeying */
    ?>
    http://peksa.se - photos by me.

  4. #4
    Join Date
    May 2005
    Location
    Bay Area, CA
    Posts
    62

    Default

    This is very useful. I am eventually going to run my own site in about 1 year I should be ready. I don't want to just start a site with out having everything I need. So yea. Good Tutorial.

  5. #5
    Join Date
    Apr 2006
    Posts
    1

    Default

    i have made the bad word filter for filtering my emails.
    I would like to know how to make certain email ids avoid this word filter I mean some of my very close friends are blocked by this word filter How to allow them sending mails avoiding this word filter ?

    How to code it ?

  6. #6

    Default

    Hmm you certainly now alot /scarasm
    example
    PHP Code:
    <?php

    function check($string)
    {
    $replace = array();
    $with = array();

    $replace[] = "hey";
    $with[] = "***";

    $replace[] = "test";
    $with[] = "monkey";

    /* just keep adding em */

    return str_replace($replace$with$string);
    }
    echo 
    check("hey, i'm testing"); /* will return ***, i'm monkeying */
    ?>

    now lets use that function...
    Testing, Popping in to say hey and good test. // Output: monkeying in to say *** and good monkey.

    see what i mean? it replaces anything with the letter's joined up i had this problem on a mates forums e.g. class would show cllove as the word ass..

    Karlos

  7. #7
    Join Date
    Dec 2005
    Location
    Co
    Posts
    3,329

    Default

    Nice way to bump a thread from 2005.




  8. #8

    Default

    Tbh i don't care when a thread was started, i like to point out the point and flaws...

    And Hello Apathy

  9. #9

    Default Help

    Is it possible to put all the words in a txt file and just matching it to the message(whereby if a badword is detected it just echo a message?) instead of replacing the words? Urgent reply needed

  10. #10

    Default

    Actually the most effective way would be to use general word to replace several words. And yes a text file can be used.

    PHP Code:
    <?php
    $bad_words 
    file("your bad words file.txt");
    function 
    CensorBadWords ($text$censor)
    {
     for(
    $i=0$i count($bad_words); $i++)
     {
      
    $text str_replace($bad_words[$i], $censor$text);
     }
     return 
    $text;
    }
    echo 
    CensorBadWords("Your Potty Mouth Here""******");
    ?>
    this would replace bad words with ****** in your badwords file it would need to be layed out like this

    Code:
    word one
    word two
    word three

Similar Threads

  1. Filter Sig
    By Ravon in forum Sigs & Manips
    Replies: 9
    Last Post: 10-30-2005, 06:59 AM
  2. All Filter sig
    By DragonsRage in forum Sigs & Manips
    Replies: 6
    Last Post: 06-21-2005, 01:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBadvanced CMPS v4.1.1