Re: Bad word filer

From: altergothen (junkmail_at_webnet.za.net)
Date: 04/25/04


Date: Sun, 25 Apr 2004 00:50:48 +0200

Try ........

<?php

function BadWordFilter($text){
 $filename = 'badwords.txt'; // txt file with one bad word per line
 $fh = fopen ($filename, "r");
 $bads = array();
 if ($fh) {
   while (!feof($fh)) {
        $buffer = fgets($fh, 4096);
        $bads[] = rtrim($buffer);
      }
 } else {
   print 'DOH! Can not open file $filename ';
 }
 fclose($fh);

 $count=count($bads);
 $count=$count-1;
 for($i=0;$i<$count;$i++) { //go through each bad word
   print "$bads[$i]<br>"; // print test to see each word
   $text = eregi_replace($bads[$i],'****',$text); //replace it
 }
    echo $text;
} // end function

BadWordFilter("This is my test word - darnit");
?>

"Brian" <brian@nrwp.co.uk> wrote in message
news:TGlic.450$YR1.307@newsfe1-win...
> Can anybody see why this is not working ?
>
>
> function BadWordFilter($text){
> $filename = 'badwords.txt'; // txt file with one bad word per line
> $fh = fopen ($filename, "r");
> $bads = array();
> if ($fh) {
> while (!feof($fh)) {
> $buffer = fgets($fh, 4096);
> $bads[] = rtrim($buffer);
> }
> } else {
> print 'DOH! Can not open file $filename ';
> }
> fclose($fh);
>
> for($i=0;$i<count($bads);$i++) { //go through each bad word
> print "$bads[$i]<br>"; // print test to see each word
> $text = eregi_replace($bads[$i],'****',$text); //replace it
> }
> return $text;
> } // end function
>
>