I have just done this today. I did it by creating an array of profane words. Then created a function to check through the input text and compare the substrings to the $profane[] array then replace the bad words with #@*! using the eregi function. Here's the code:
$replace = "#*@!";
while (list(, $swearWord) = each($profan))
{
if (strstr(strtoupper($inputText), strtoupper($swearWord)))
{
if (strtoupper($inputText) == strtoupper($swearWord))
{
$inputText=$replace;
}
$inputText = eregi_replace("$swearWord([a-zA-Z])", "$replace\1", $inputText);
$inputTitle = eregi_replace("([a-zA-Z])$swearWord$", "\1$replace", $inputText);
while (eregi("([a-zA-Z])($swearWord)([a-zA-Z])", $inputText))
{
$inputText = eregi_replace("([a-zA-Z])($swearWord)([a-zA-Z])", "\1$blurb\3", $inputText);
}}
}}
return array($inputText);
This works great! and doesn't pick through words such as 'assets'.