Well i am trying to add a badwords checker in a form where if there is a badword entered a error is displayed when submit do you know of any function which would do this ??
I think you can get some idea about that from here http://snipplr.com/view/6332/censor-bad-words-with-regexp/
<?php $badwords = array('badword1','badword2','badword3','badword4'); $badwords = explode(",", $badwords); foreach($badwords as $badword) { preg_replace("/$badword/i", "FIXED WORD", $badword); } ?> PHP: The preg $badword can be replaced with say $text, so that it doesn't just fix the array, but it fixes a paragraph. Example: <?php $text = "hello mother badword1s!! i've been on t3h badword1ing interwebs for some time now. now go eat badword2 and lets jump around like a bunch of badword3holes and be badword4s!!!!"; $badwords = array('badword1','badword2','badword3','badword4'); $badwords = explode(",", $badwords); foreach($badwords as $badword) { preg_replace("/$badword/i", "*****", $text); } echo $text; ?> PHP: This would output... Hope that helps
is it possible like if there is a badword it will tell that its false and give a error .. i mean the function
no what i want is like a form checker like its a email submission people put badwords in thier emails all i want is that if there is a badword the function returns false
may be following function can be helpful.. function contains_badword($str_to_check) { $found = false; $bad_words = array('badword1', 'badword2', 'badword3', 'badword4'); foreach($bad_words as $bad_word) { $found = preg_match("/$bad_word/i", $str_to_check); if($found > 0) break; } if($found > 0) return true; else return false; } PHP: