Try using this code snippet and modify it to your needs:
$badwords = array('ass', '@!#$');
$strText = '@!#$, this ass keeps harrassing me!';
$strSearch = '';
for ($iIndex = 0; $iIndex < sizeof($badwords); $iIndex++)
{
if ($iIndex == 0)
$strSearch.= '\b';
else
$strSearch.= '\b|\b';
$strSearch.= $badwords[$iIndex];
}
$strSearch.= '\b';
$blnBadWords = preg_match("/$strSearch/i", $strText);
if ($blnBadWords)
{
do something
}
else
{
something else
}
You can easily change this to replace the offending text as well by changing these lines:
$blnBadWords = preg_match("/$strSearch/i", $strText);
if ($blnBadWords)
{
do something
}
else
{
something else
}
to:
$strText = preg_replace("/$strSearch/i", '%@$', $strText);
now $strText contains a censored version of the input text
You can take it one step further by creating a file with a list of bad words, and then reading that into an array. Or you can just have an include file that contains an array of all the 'bad' words.
hth
p.