I have this code below which works ok ish.
$swearWords = file("blacklist.txt");
foreach ($swearWords as $naughty)
{
$post = str_ireplace(rtrim($naughty), "<b><i>(oops)</i></b>", $post);
}
The problem is with words that contain thee swear words..
for instant “Scunthorpe” has a bad word within it. this code changes it to S(oops)horpe.
Any ideas how i can fix this ? do I need to
You can replace your
str_replace()with apreg_replacethat ignores words that have leading and/or trailing letters, so a swear word is only replaced if its standing alone:Note that it still allows swear words like “aCUNT”, “soFUCKINGstupid”, … i don’t know how you could even handle that.