Ralf: Problem bei einem Wortfilter Script

Beitrag lesen

hmm .. heisst das wenn ich ein Backslash vor die Worte setz kümmerts ihn nicht ob irgendwo in dem wort groß oder kleinbuchstaben vorkommen? wenn ja wie könnte ich den backslash dann in das array integrieren! weil das array wird erst mit dem auslesen des TXT-Files generiert :-/

Hier mal mein script:

function wordfilter($text)
{
global $badfile;
/**** Reading out data from the txt-File and put them into an Array **************/
$badwords = array();

$openfile = fopen($badfile, "rb");
$getcontent = file($badfile);

for($i = 0; $i < count($getcontent); $i++)
    {
  $trimmedWord = trim($getcontent[$i]);
  $trimmedWord = strtolower($trimmedWord);
  array_push($badwords, $trimmedWord);
  }
fclose($openfile);
/*********************************************************************************/

/**** Censoring the Words *****************************************************/
$censoredWords = array();

for($i = 0; $i < count($badwords); $i++)
    {
  $countChars = strlen($badwords[$i]);
  for($j = 0; $j < $countChars; $j++)
      {
    if($j == 0)
       {
      $firstLetter = substr($badwords[$i],0,1);
      $censoring[$i] .= $firstLetter;
      }
    else
       {
      $censoring[$i] .= "*";
      }
    }
  array_push($censoredWords, $censoring[$i]);
  $text = str_replace("".$badwords[$i]."", $censoredWords[$i], $text);
  }
/******************************************************************************/
return $text;
}
$text = wordfilter($text);
echo $text;

wie man sieht habe i ch überall nur arrays die von einander abhängen! wirkliche daten habe ich in dem Gesamten Quelltext nicht, die werden nur importiert...