954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Create a vulgar language filter

I have an email form on my site which has an action to a php page. The php page detects whether the user has entered a name and email, if they haven't it directs them back, if they have it sends an email to me. I want to add a php cussword filter that would prevent the message from being sent if the message contains any words that i want to block out. Does anyone know how i can accomplish this?

Bubbleboy
Light Poster
25 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This is a bit rough, there's probably a better way. But this works.

// Array of blocked words
$bad_words[0] = "badword1";
$bad_words[1] = "badword2";
$bad_words[2] = "badword3";
	
foreach($bad_words as $word) {
	if(strpos(strtolower($email_message), $word) !== false) {
	      // Set flag to check when you exit the loop
              $message_ok = false;
	}
}

if(!$message_ok) {
    // Some code to be executed if a vulgar word is found
}
Lsmjudoka
Junior Poster in Training
75 posts since Apr 2009
Reputation Points: 10
Solved Threads: 9
 

If the email is only going to you - what's the problem? Spam? If you're upset by profanity, I bet it's gonna upset the f*** out of you to type in those words which you wanna filter out in the first place.

IF you're worried about automated spam, put a captcha field in your form. Also, have a timeout feature that only allows one post per 15 minutes from a particular IP address. Coz I could send b0ll0ck5 to you, you BUGG3R, and you probably won't pick it up. (Sorry no offence!)

Having the filter won't hurt, but it won't stop all of the brown stuff slopping through the mailbox.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: