Location: PHPKode > projects > Hotseat Corner > lib/HSUtils/Filter.class.php
<?php 
class HSUtils_Filter{
        public static function runFilter($string){
                $badwords=file("../etc/unsafe_words.txt");
                foreach($badwords as $curse_word){
                        $curse_word=str_replace("\r","",$curse_word);
                        $curse_word=trim($curse_word);
                        $stars="";
                        $cw_exp="";
                        $length = strlen($curse_word);
                        for($i=1;$i<=$length;$i++){
                                $stars.="*";
                        }
                        for($i=0;$i<$length;$i++){
                                $cw_exp.="[" . strtoupper(substr($curse_word,$i,1)) . strtolower(substr($curse_word,$i,1)) . "]";
                        }
                        $words[]=array("match"=>$cw_exp,"replace"=>$stars);
                }
                $postwords = preg_split("/([^a-zA-Z0-9'])/",$string,null,PREG_SPLIT_DELIM_CAPTURE);
                for($i=0;$i<count($postwords);$i++){
                        foreach($words as $word){
                                if(preg_match("/" .$word["match"] . "/", preg_replace("/[^a-zA-Z0-9]/","",$postwords[$i]))==1){
                                        $postwords[$i]=preg_replace("/(" .$word["match"] . ")/",$word["replace"], preg_replace("/[^a-zA-Z0-9]/","",$postwords[$i]));
                                }else{
                                        $postwords[$i]=preg_replace("/(" .$word["match"] . ")/",$word["replace"], $postwords[$i]);
                                }
                        }
                }
                return join("",$postwords);
        }
}
?> 
Return current item: Hotseat Corner