...

View Full Version : anyone no a a script/site ect for a filter



netpets
02-04-2004, 05:30 PM
anyone got a site/script for a bad word filter

Philip M
02-04-2004, 06:23 PM
Here is what I use:
function smutEnginesubject() {
var smut="*#*?*&*%*!*#*?*&*%*!*#*?*&*%*!";
var badnum=0;

cmp="bad words go in here with a space between and a space at the end ";

txt=document.adinputform.AdSubject.value;
for (var i=0;i<62;i++) { #replace 62 by number of bad words
pos=cmp.indexOf(" ");
wrd=cmp.substring(0,pos);
wrdl=wrd.length;
cmp=cmp.substring(pos+1,cmp.length);
while (txt.indexOf(wrd)>-1) {
pos=txt.indexOf(wrd);
txt=txt.substring(0,pos)+smut.substring(0,wrdl)+txt.substring((pos+wrdl),txt.length);
badnum=badnum+1;
}
}
document.adinputform.AdSubject.value=txt;
if (badnum>0) {
alert ("Your ad heading contains " +badnum +" word\(s\) which are not permitted.\n\nYou may wish to change the heading to make it more acceptable.");
document.adinputform.AdSubject.focus();
return false;
}

var xflag=0;
var badchars="/\*-#";
for (var x=0;x < txt.length;x++) {
if (badchars.indexOf(txt.charAt(x))!=-1) {xflag++}
}
if (xflag>3) {
document.adinputform.reset();
alert ("No thanks, "+truename+"! We don\'t want that sort of ad on our board! ");
blocked=1;
}
}

Vladdy
02-04-2004, 06:27 PM
Client side filtering can be easily circumvented. Server side scripting should be used for a feature like that.

Still your script is very inefficient:
First, your function is tied to a particular form field, which makes it non-reusable. Much better approach is to make function take the string to be filtered as an arguement and return the filtered string (who really cares how many bad words have beed found).
Second, your string manipulation can be done much better with the use of regular expressions (even if you insist on using the list of bad words as a space separated string instead of an array):



function filterBadWords(instring)
{ var badwords = "your bad words here";
bwarray = badwords.split(' ');
for(var i=0; i<bwarray.length; i++)
{ re = new RegExp(bwarray[i],'ig');
// replace string can also be an arguement
instring.replace(re,'####');
}
return instring;
}

netpets
02-04-2004, 10:04 PM
theres a problem its not working

Philip M
02-05-2004, 07:29 AM
Thank you Vladdy. I take on board what you say. However, although inefficient the thing still works.

I guess that to you as a professional efficiency is important if your scripts are being accessed many times a day. Mine is accessed perhaps twice a week. But I am keen to learn and will make the alterations you suggest.


Netpets - as it stands the script is only an example. You will
need to make alterations to the form name and field name.

Also, you must delete the #replace 62 by whatever comment.

Garadon
02-05-2004, 09:36 AM
I took Vladdy suggestion and altered it, I took the liberty to test it with some bad words :), this script checks up on words opposed to vladdys initial one that checked up on letter constallations. the splitter is * and remember a space on eash side of the bad word in the bad word sting, the alert in the start is just a test.


<script>
alert(filterBadWords('This is a bad word replacer not wordperfect'));
function filterBadWords(instring)
{
var badwords = " bad * word * gimp ";
bwarray = badwords.split('*');
for(var i=0; i<bwarray.length; i++)
{
re = new RegExp(bwarray[i],'ig');
// replace string can also be an arguement
instring=instring.replace(re,' #### ');
}
return instring;
}
</script>

Vladdy
02-05-2004, 01:31 PM
Garadon, the space is only one of the possible word boundaries. Other can include period, comma, new line, etc.
If you prefer to check on complete words, constuct the regular expression with \b:
re = new RegExp('\\b' + bwarray[i] + '\\b','ig');

Garadon
02-05-2004, 02:56 PM
Ofcourse ur rigth lol :), but why even use a badword filter its a bad idea to start with. Freedom of speech and all, and to think how many thousands of words that could be considered bad. In short its a complete waste of time if you ask me.

Philip M
02-05-2004, 07:34 PM
If you prefer to check on complete words, constuct the regular expression with \b:
re = new RegExp('\\b' + bwarray[i] + '\\b','ig');


Well, yes.

Otherwise people in Penistone and Scunthorpe may feel discriminated against and sue you for zillions of dollars for emotional distress etc.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum