Page 1 of 1

Check for bad words in a textarea before submition??

Posted: Thu Jul 10, 2003 4:54 am
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.

Posted: Thu Jul 10, 2003 5:48 am
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 '#%^@'.
?>

Posted: Thu Jul 10, 2003 7:54 am
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.