PHP strpos() as a way to implement an swear word filter
Two things I have noticed:

You remove all non-alpha-numeric characters, apart from the dash and space characters. I don't see what this adds to your filter? Clearly all the other characters are never part of your swear words, so why bother to remove them? It could, in theory, have unpredictable consequences, because formerly separated characters might form new words. Instead of removing you could replace the characters with a space, but my suggestion is to just don't do this step at all.

strpos() is case sensitive, that would mean your function won't find &quot;BadWord&quot; or &quot;BADWORD&quot; unless you add all these variants to your array. Better use stripos() which is case-insensitive.