Web Analytics Made Easy -
StatCounter Can't load text file into array - CodingForum

Announcement

Collapse
No announcement yet.

Can't load text file into array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't load text file into array

    I have adapted this function to filter profanity from a guestbook. Somehow the text file does not fill the array. Each entry in the file ends with a newline. If I define the array in the function, the function works fine, replacing the offensive words with *s. Can someone tell me what I might have done wrong with either the file or the function?


    function language_filter($comments)
    {
    $obscenities = file("foul_language.txt");
    foreach ($obscenities as $curse_word)
    {if (stristr(trim($comments),$curse_word))
    {$length=strlen($curse_word);
    for ($i = 1; $i <= $length; $i++)
    {
    $stars .= "*";
    }
    $comments = eregi_replace($curse_word, $stars, trim($comments));
    $stars = "";
    }
    }
    return $comments;
    }

  • #2
    I believe the "\n" is going to be part of each element in your $obscenities array. Try using trim() on $curse_word.

    Comment


    • #3
      That did it. Thanks!

      Comment

      Working...
      X