Blocking profanity using php

Discussion in 'PHP' started by derek34, Dec 6, 2007.

  1. #1
    Hi I have a website that has an online form. Recently, people have been using profanity and extreme swearing in malicious messages to me. Is there an easy way to block certain words?
    any help is appreciated as always
    Thanks!
    - Derek
     
    derek34, Dec 6, 2007 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    create an array or a table that will hold all the malicious contents or words.
    what ive done is before they can submit a post i will search the contents for the restricted words...
    well thats what im going to do..
     
    bartolay13, Dec 6, 2007 IP
  3. derek34

    derek34 Guest

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you think you could provide some sample code to get me started in the right direction???
     
    derek34, Dec 6, 2007 IP
  4. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This might help :)

    
    $form = 'hello world i am submitting to a website';
    
    $badWords = array('these', 'are', 'your', 'swear', 'words');
    
    foreach ($badWords as $word)
    {
    	if (strpos($form, $word) !== FALSE)
    	{
    		$swearing = TRUE;
    		break;
    	}
    }
    
    if (isset($swearing))
    {
    	echo 'There were swear words';
    }
    else
    {
    	echo 'There were no swear words';
    }
    
    PHP:
    Not perfect but it should get you started
     
    tonybogs, Dec 6, 2007 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    I think this would be better.

    
    $form = 'hello world i am submitting to a website';
    $badWords = array('these', 'are', 'your', 'swear', 'words');
    
    $form = str_replace($badWords, "[censored]", $form);
    
    Code (php):
    Yes you can use arrays in str_replace()
     
    Kaizoku, Dec 6, 2007 IP