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.
Check for bad words in a textarea before submition??
Moderator: General Moderators
- redhair
- Forum Contributor
- Posts: 300
- Joined: Fri May 30, 2003 4:36 pm
- Location: 53.23N-6.57E
- Contact:
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:
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 '#%^@'.
?>