Closed Thread
Results 1 to 10 of 10

Thread: file array

  1. #1
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805

    file array

    how do I make a file where each line is part of an array.
    basically so i can do something this:

    $filtered = str_replace($foul, "", $fullabrv);

  2. #2
    NLC DarkBlood is just really niceDarkBlood is just really niceDarkBlood is just really niceDarkBlood is just really nice DarkBlood's Avatar
    Join Date
    Aug 2002
    Location
    Madison, WI
    Posts
    4,506
    You have to do a while statement to get the files first, (can view one of those at http://www.php.net 's online documentation (search for: readdir function).) then try and get this.
    Last edited by DarkBlood; February 10th, 2006 at 12:49.

  3. #3
    Senior Member BeIIy is an unknown quantity at this point
    Join Date
    Feb 2005
    Posts
    120
    Code:
    $badwords = file("./badwords.txt");
    foreach($badwords as $badword) {
      $filterthis = eregi_replace($badword, "", $filterthis);
    }
    change eregi_replace to str_replace if you want it to be case-sensitive
    http://www.j-fx.ws - free website templates
    http://www.j-fx.ws/tagbox/ - my shoutbox script
    http://www.j-fx.ws/ffh/ - my file host script

  4. #4
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    great, thanks BeIIy!!

  5. #5
    Super Moderator#1 stuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond reputestuffradio has a reputation beyond repute stuffradio's Avatar
    Join Date
    Oct 2005
    Location
    BC, Canada
    Posts
    7,300
    You could do what BeIIy did but here is what I did.
    [php]
    <?php
    include("config.php");
    global $text;
    $text = str_replace("word", "**it", $text);
    $text = str_replace("word", "**ck", $text);
    $text = str_replace("word", "****er****er", $text);
    ?>[/code]

    I named that file filter.php so what you do is when you have the user post, just include filter.php and when they post the file or whatever you want to have filtered, have a field that is the message that they're posting <input type="text" name=text> the query would be like

    mysql_query("INSERT INTO table_name (blah, blah1, blah2, text) VALUES ('$blah', '$blah1', '$blah2', '$text')");

    Than in the database it'll replace whatever is in the textfield with what you set it to in the filter.php file.

  6. #6
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    just got the time to try BeIIy's code out and it doesnt work

    PHP Code:
    $badwords file("./includes/bad.txt");
    foreach(
    $badwords as $badword) {
    $fullabrv eregi_replace($badword""$fullabrv);

    and stuffradio, thanks but thats not what i wanted. I wanted it to get each line of a file and put it into an array.

  7. #7
    Senior Member BeIIy is an unknown quantity at this point
    Join Date
    Feb 2005
    Posts
    120
    Whoops. I forgot that it leaves the linebreak characters on each line.
    Code:
    $badwords = file("./badwords.txt");
    foreach($badwords as $badword) {
      $word = str_replace("\r","",str_replace("\n","",$badword));
      $filterthis = eregi_replace($word, "", $filterthis);
    }
    That should work. lol
    http://www.j-fx.ws - free website templates
    http://www.j-fx.ws/tagbox/ - my shoutbox script
    http://www.j-fx.ws/ffh/ - my file host script

  8. #8
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    Quote Originally Posted by BeIIy
    Whoops. I forgot that it leaves the linebreak characters on each line.
    Code:
    $badwords = file("./badwords.txt");
    foreach($badwords as $badword) {
      $word = str_replace("\r","",str_replace("\n","",$badword));
      $filterthis = eregi_replace($word, "", $filterthis);
    }
    That should work. lol
    yep, that works. thanks loads

    One more thing if you dont mind

    how do i replace them with asterix's (like the f word would be replaced with ****, the b word would be replaced with *****)?

  9. #9
    Senior Member BeIIy is an unknown quantity at this point
    Join Date
    Feb 2005
    Posts
    120
    Code:
    $badwords = file("./badwords.txt");
    foreach($badwords as $badword) {
      $word = str_replace("\r","",str_replace("\n","",$badword));
      $stars = "";
      for ($i = 1; $i <= strlen($word); $i++) { $stars .= "*"; }
      $filterthis = eregi_replace($word, $stars, $filterthis);
    }
    http://www.j-fx.ws - free website templates
    http://www.j-fx.ws/tagbox/ - my shoutbox script
    http://www.j-fx.ws/ffh/ - my file host script

  10. #10
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    works like a charm BeIIy really appreciated

Closed Thread

Bookmarks

Posting Permissions

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