View Single Post
Old 03-10-2010, 04:16 AM   #1 (permalink)
Tim Dobson
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default word filter help

I have this code:
PHP Code:
<?php
                    
$myFile 
"quotes.txt";
$fh fopen($myFile'r');
$ToFilter fread($fhfilesize($myFile));
fclose($fh);
function 
LangFilter($ToFilter)

{

   
// Open the foul.txt for extracting the foul words

   
$Foul = @file("foul.txt");

   
// Loop through the foul words

   
foreach ($Foul as $FoulWord)

   {

      
// Store the current foul word in a variable

      
$FoulWord trim($FoulWord);

      
// If there's a match for the fould world inside the string

      
if (preg_match("/".$FoulWord."/i"$ToFilter))

      {

         
// Get the word length, so that we know how many characters

         // we need to replace with asterisks

         
$WordLength strlen($FoulWord);

         
// Loop through the word's characters

         
for ($i 1$i <= $WordLength$i++)

         {

            
// Replace the characters of the foul word with * (asterisks)

            
$RepChar .= "*";

         }

         
// Replace the dirty string with the filtered string

         
$ToFilter eregi_replace($FoulWord$RepChartrim($ToFilter));

         
$RepChar "";

      }

   }

   
// Return the new string

   
return $ToFilter;

}
echo 
$ToFilter;
?>
quotes.txt is data that is to be loaded to the page and foul.txt is a text file containing all words that are to be filtered. Although its not working... obviously its not right could somone plz correct me, new to php!
Tim Dobson is offline  
Reply With Quote