|
Home All Articles Contact Zawgyi Myanmar Font |
|
Home >> Snippet List >> Snippet Name Bad Word FilterDescription Replaces bad words, censoring the text passed in automaticallyPHP Snippet <? // BadWordFilter // This function does all the work. If $replace is 1 it will replace all bad words // with the wildcard replacements. If $replace is 0 it will not replace anything. // In either case, it will return 1 if it found bad words or 0 otherwise. // Be sure to fill the $bads array with the bad words you want filtered. FUNCTION BadWordFilter(&$text, $replace){ // fill this array with the bad words you want to filter and their replacements $bads = ARRAY ( ARRAY("butt","b***"), ARRAY("poop","p***"), ARRAY("crap","c***") ); IF($replace==1) { //we are replacing $remember = $text; FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it } IF($remember!=$text) RETURN 1; //if there are any changes, return 1 } ELSE { //we are just checking FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1 } } } // this will replace all bad words with their replacements. $any is 1 if it found any $any = BadWordFilter($wordsToFilter,1); // this will not repace any bad words. $any is 1 if it found any $any = BadWordFilter($wordsToFilter,0); ?> |
|
All photograph,logos, articles, comments and trademarks etc, in this site are property of their respective owners.All the rest (c) 2006 by PhpMyanmar.com. |