03-10-2010, 04:16 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Feb 2010
Posts: 69
Thanks: 16
|
word filter help
I have this code:
PHP Code:
<?php
$myFile = "quotes.txt";
$fh = fopen($myFile, 'r');
$ToFilter = fread($fh, filesize($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, $RepChar, trim($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!
|
|
|
|