Check for bad words in a textarea before submition??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
garagedj1
Forum Newbie
Posts: 1
Joined: Thu Jul 10, 2003 4:54 am
Location: London

Check for bad words in a textarea before submition??

Post by garagedj1 »

does anyone know a simple script to check for bad words in a textfield and a textarea before submition? I would like the script to check through before the form data is entered into my database.

Thanks.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

First, Look at the preg_replace function on php.net
http://php.net/manual/en/function.preg-replace.php

(You also might want to take a look at preg_match and then at the array function, to create an array of bad words you dont want to show up. All well described on the webpage i just refered above.)

preg_replace can search for your bad word, and replace it by something else.

preg_replace example:

Code: Select all

<?php

$yourtext=preg_replace("/BadWord/", "#%^@", $yourtext);

//If 'BadWord' is in $yourtext, it will be replaced by '#%^@'.
?>
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

The above solution is probably what you'll want to go with, but if you needed to do it client-side (before the form is even submitted) then you'd be looking at implementing a preg_replace-style solution in Javascript, just FYI.
Post Reply