/    Sign up×
Community /Pin to ProfileBookmark

Making a forum disableing words, how do i dissable words so that they turn into ****

Making a forum disableing words, how do i dissable words so that they turn into **** for bad words

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreMay 31.2003 — 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.
Copy linkTweet thisAlerts:
@NevermoreMay 31.2003 — Incidentally, for a demonstration of PHP language filtering, check out http://members.lycos.co.uk/cijori/input.php
Copy linkTweet thisAlerts:
@RibeyedMay 31.2003 — 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
Copy linkTweet thisAlerts:
@NevermoreMay 31.2003 — 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.
Copy linkTweet thisAlerts:
@jeffmottMay 31.2003 — [b]reg=/[b|B][a|A][d|D]/;[/b][/quote]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.,[size=2]/bad/i[/size]
Copy linkTweet thisAlerts:
@NevermoreMay 31.2003 — I've only recently started learning regular expressions, so I'm not perfect... yet.
Copy linkTweet thisAlerts:
@CharlesMay 31.2003 — [font=georgia]I don't know anything about PHP, but I cannot believe that it doesn't support regular expression flags. In perl [font=monospace]s/bad/***/gi[/font] would substitute "***" for your bad work globally and ignoring case. [font=monospace]s/bW*aW*dW*/***/gi[/font] would do the same thing but would also look for "b*a*d" and such.[/font]
×

Success!

Help @wildwobby spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...