View previous topic :: View next topic |
Author |
Message |
vibhavram -
Joined: 30 May 2010 Posts: 2 Location: Hyderabad
|
Posted: Sun Sep 25, 2011 10:06 am Post subject: Any one enhance this code to filter badwords. |
|
|
I am using the following php functions to filter bad words from the user generated content. This is still not sufficient to filter in a better way since users are posting words added with spaces like for word 'badword' they are posting like 'b a d w o r d'.
Here are the functions
Code: | function load_bad_words(){
global $bad_words;
$bad_words = @file_get_contents(CFDSPATH . "badwords.lst");
$bad_words = preg_split( '/\r\n|\r|\n/', $bad_words );
}
function strip_abbusive_words($str){
global $bad_words;
foreach($bad_words as $bad_word){
$bad_word_regex = '/' . ($bad_word[0] == '*' ? '': '\b') . str_replace('*', '', $bad_word) . ($bad_word[(strlen($bad_word)-1)] == '*' ? '': '\b') . '/i';
$str = preg_replace($bad_word_regex, '', $str);
}
return $str;
}
|
Can any one enhance these functions to filter bad words with combinations of spaces and special characters? _________________ I am a professional developer of web content having expertise in PHP and Javascript working as Manager for a Technical dept of a software development company. My newest development is Free Classifieds |
|
Back to top |
|
|
Toasty -
Joined: 21 Feb 2008 Posts: 298 Location: Chicago, IL
|
Posted: Sun Oct 02, 2011 9:04 am Post subject: |
|
|
How would one do assassinate or assume if you're stripping out spaces to remove bad words?
No matter how much filtering you put in, people will find a way to f*ck with your code until you realize you couldn't do 5hit about it.
^If you catch my drift with the words I put in there :P _________________ Audit the secure configuration of your server headers! |
|
Back to top |
|
|
|