Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I believe the "\n" is going to be part of each element in your $obscenities array. Try using trim() on $curse_word.

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That did it. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •