Try this SmutEngine:-
Code:
<html>
<head>
<script type="text/javascript">
var notAllowed = [["*"], [" sex"], [" rape"], ["damn"], [" ***]", ["arse"], ["porn"], ["intercourse"], ["erotic"], ["pervert"]];
// Filters sex but not Essex, filters rape but not drape, filters a*s*s (blocked on this site!) but not pass
// But then kinkysex, gangrape and fatass are not blocked. You can't win!
function checkWord(txt){
txt = " " + txt.value; // catch initial badwords starting with a space
lctxt = txt.toLowerCase();
for (var i = 0; i < notAllowed.length; i++) {
if (lctxt.indexOf(notAllowed[i]) != -1){
alert ('The word "' + notAllowed[i] + '" is not allowed!');
var rep = txt.substr(0, lctxt.indexOf(notAllowed[i]));
if (notAllowed[i] !="*") {
if (/[^\s]$/.test(rep)) { // add a space at end of text if not one already
rep = rep + " ";
}
}
rep = rep.replace (/^\s/, ""); // remove initial space again
document.getElementById("myText").value = rep;
return false;
}
}
}
</script>
</head>
<body>
<form name = "myForm">
<textarea name="myText" rows="10" cols="50" onkeyup="checkWord(this)"></textarea>
</form>
</body>
</html>
The advantage is that it is case insensitive and notAllowed words are removed as they are typed, which may help to discourage abusers. This is perhaps better than replacing the badwords by **** which the reader may guess.
But as always bad-word or bad word or b.a.d.w.o.r.d will get through.
It is impossible to filter badwords completely. The script will filter for gangrape if the notAllowed word is 'rape' (no leading space) but that will also filter out drape and grape and scrape. I guess that might be accepted as drape, grape and scrape are uncommon words. Likewise kinkysex is filtered out if the notAllowed word is 'sex' (no leading space) but the penalty is that Essex and Sussex are also blocked.
If you mean erase badwords displayed on someone else's site, then that cannot be done. The remedy is obvious - don't visit sites which permit bad language.