- This topic has 5 replies, 4 voices, and was last updated 19 years, 4 months ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.
Home › Forums › Archives › Computer Support › Computer Support Discussion › Badword Filter
I wrote this script that blocks out badwords.
[PHP]for($gx=-1;$gx<$tb;$gx++) {
if($badwords[$gx] != “”) {
$str= eregi_replace(rtrim($badwords[$gx]), “@!&^*%”, $str);
}
}[/PHP]
The only problem is that it currently takes text and will block a badword inside a regular word.
Example:
CLASS = CL@!&^*%
ASSASSINATION=@!&^*%@!&^*%ination
How can I prevent this?
Thank you!
You need some sort of word-break filter. I don’t know if you’re using regular expressions in that array or if you’re just using a list of bad words, but there’s a regex character b that specifies word boundaries. That might help.
I forgot to add this part (goes above code):
[PHP]$badwords= file(“badwords.txt”);
$tb=count($badwords);[/PHP]
The words are located in badwords.txt posted like below (one under eachother):
BAD
BAD
BAD
BAD
BAD
BAD
My php knowledge is very minimal, but would it work if you included required spaces…or similar to html’s
that’s why I suggested a regex non-word character as the break point. That way it would still work at the end of a sentence but not block words like assassination. i believe it qualifies ‘non-word characters’ as anything except the letters A-Z and maybe 0-9, though I’m not sure about the numbers.
Regex Tutorial – b Word Boundaries
PHP: Regular Expression Functions (POSIX Extended) – Manual
Tigerblade is correct in that you need to use b for your boundary. Please read the above documentation on implementing this.