#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    The script is supposed to read all files in that directory, search each file for $search (which is defined by a form) and then return the file if $search is found, go on if it isn't

    I have .txt files numbered from 1 - 123 in the same dir, when i try to readfile() instead of the file()/if(in_array)) it works just fine, only in_array does not work the way its supposed to.
    Yes, i have php4.


    $file = 1;
    while (file_exists($file . ".txt")) {
    $file++;
    }
    --$file;
    for ($count = $file; $count > 0; $count--) {
    echo "<pre>";
    $file_array = file ($count . ".txt");

    echo "<br>";
    if (in_array ($search,$file_array)) {
    readfile ($count . ".txt");
    }
    echo "</pre>";
    }



    [This message has been edited by Who (edited October 18, 2000).]
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    What do you mean it doesn't work? Do you get an error or does in_array() never evaluate to true?

    If the latter, are you sure there is an ENTIRE line in the file that matches $search?

    Also, I'm not sure on the case sensitivity of in_array(). It's not in the manual and I've never used it for strings (assuming you are).
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    it doesn't seem to do anything, so i guess it evaluates to false, i've tried variations where $search is a entire line, or just one word, neither seems to work.

    (Btw, i'm not using in_array for a string, but for a array.. otherwise i'd use eregi)
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    For in_array() to work the EXACT value must be in one of the array elements, not just a part of the element..

Similar Threads

  1. Replies: 4
    Last Post: May 18th, 2004, 05:21 AM
  2. Pointer problem in opening a file
    By LAKI in forum C Programming
    Replies: 13
    Last Post: February 11th, 2004, 08:27 AM
  3. Replies: 1
    Last Post: February 8th, 2004, 01:59 PM
  4. Upload file name problem
    By clio in forum PHP Development
    Replies: 1
    Last Post: February 6th, 2004, 06:19 AM
  5. Problem with opening a file
    By Psantiago in forum C Programming
    Replies: 3
    Last Post: February 3rd, 2004, 07:31 PM

IMN logo majestic logo threadwatch logo seochat tools logo