Page 1 of 1

Badwords are bad, how can i get rid of them?

Posted: Wed Jul 03, 2002 2:17 am
by chris12295
i have a database table of bad words, how can i find all occurences of the words in a form text field and replace them with a blank?

Posted: Wed Jul 03, 2002 3:04 am
by twigletmac
If you put all the bad words into an array you can use str_replace() to change any occurances to blanks:

Code: Select all

$badwords = array('foo', 'bar', 'ick');
$my_dirty_text = 'This is a foo bar ick day';
$my_clean_text = str_replace($badwords, '', $my_dirty_text);
echo $my_clean_text;
Outputs

Code: Select all

This is a  day
Mac