Click to See Complete Forum and Search --> : Making a forum disableing words, how do i dissable words so that they turn into ****


wildwobby
05-30-2003, 11:59 PM
Making a forum disableing words, how do i dissable words so that they turn into **** for bad words

Nevermore
05-31-2003, 04:07 AM
What language are you using? In PHP I would use str_replace() to replace 'bad words' even if they were inside another word. I wouldn't use regular expresiions because they could match other, 'none-bad' words.

This can be done in JavaScript, but since you can't run a forum with JavaScript, I wouldn't bother. If you do want JavaScript code to do it, this should do the trick:

reg=/[b|B][a|A][d|D]/;
newstr=strings.replace(reg,"b*d");

reg is a regular expression that matches the word 'bad' whatever the case of each letter. The next line is matching the regular expression to the string and filtering out the word 'bad' by asterisking the a. To change this script, just change the letters in the first line, by putting the different case each letter can be in square brackets seperated by a |. e.g.
[g|G][o|O][o|B][e|E][r|R] would match goober, Goober, GoObEr etc. Then change the word you want to replace it with in the second line.

If you need any more help customizing it, just ask.

Nevermore
05-31-2003, 05:02 AM
Incidentally, for a demonstration of PHP language filtering, check out http://members.lycos.co.uk/cijori/input.php

Ribeyed
05-31-2003, 05:12 AM
Hi,
had to do this for a client recently, but couldn't find much help, however i did get around by using ASP and a database.
I created a table call tblWords with 2 fields BadWord and ReplaceWord.
I then coded into my ASP a find a replace against all the words in the table, replacing any word that appeared in the table with the replaceWord.
Tried to find a completed list of "swear/bad words" but had no luck with that, so i had to make my own, lol.

If you need the list i have i would be happy to somehow send it to you in whatever format you need.
Ofcourse my list will not be complete so i created a page for my client where they can add more to the list.

Hope this helps

Nevermore
05-31-2003, 05:17 AM
The problem with accessing a database for the words is that if it takes a long time (for a long message), you can impair the performance of your database. For that reason, I find it easier to hard-code the filtering into the code. Of course, if the route taken is JavaScript, the problem is academic.

jeffmott
05-31-2003, 07:23 AM
reg=/[b|B][a|A][d|D]/;This will actually match ||| or Ba| or b|D, and such. There is also an i flag to indicate case insensative so you do not have to provide alternates for every character. e.g.,/bad/i

Nevermore
05-31-2003, 09:25 AM
I've only recently started learning regular expressions, so I'm not perfect... yet.

Charles
05-31-2003, 03:33 PM
I don't know anything about PHP, but I cannot believe that it doesn't support regular expression flags. In perl s/bad/***/gi would substitute "***" for your bad work globally and ignoring case. s/b\W*a\W*d\W*/***/gi would do the same thing but would also look for "b*a*d" and such.