Forum Moderators: open
Im not sure if anyone can actually help me with this. I am trying to filter out swear words if they are entered into a forum i am building.
I do actually have the script working. So if someone enters say "you are a (sear word)", the code replaces the swear word with the relevany number of "*"'s.
So in this sense i am quite happy with it. The swear words are all stored in a DB, and basically when someone starts a new thread or replies to an existing thread, there comments are checked for any words matching those in the DB. If there is a match, the word is replaced.
Sounds fine.
However, the problem comes in when someone types a word that contains a swear word, but itself is not actually a swear word.
For example, if someone entered "I support arsenal FC", the script would return "I support ****nal" because it has replaced the instance of arse.
Does anyone know of a way i can get around this? I have tried entering the words into the database as (space)swearword(space), but if the swear word is the first or last word in the message then it is not picked up.
Is there anyway i can count the characters of the word in the string to make sure it matches the length if the swear word i.e. arse is 4 characters long, arsenal is 7, so do not replace the arse part?
The code I am using is just the simple Replace function:
Message = Replace(usermessage, wordfromDB, numberofstars)
All help appreciated.
Cheers
Webboy
if the message entered by the user was "you are an arse", the word arse would not be picked up, because it does not match the " arse " in the database. There is no space after it.
Looks like this is going to be a tricky one to solve!
Any more thoughts would be appreciated.
[4guysfromrolla.com...]