Results 1 to 1 of 1

Thread: question if I can rewind feof function for every loop

  1. #1
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post question if I can rewind feof function for every loop

    im a newbie in php
    what im trying to do is, i want to compare if there's a similar word in my array in myfile per line. at first iteration the $inc=0 goes inside my while loop, but other iteration will not go inside my while, i think its because feof already at the end of my file. So what did is, i put rewind function, but it happened only the first two iteration works and other dont.

    what function can i use that every iteration, feof will check from the very first line of my file.

    sorry for my english.

    Here's the code below:

    Code:
    $write_file = "myfile.csv";
    $similar_acc = array("1","2");
    $ctr = count($similar_acc);
    $inc = 0;
    $handle = fopen($write_file,"r");
    
    for($inc = 0; $inc<=3;$inc++)
    {
           echo $inc."\n";
           while(!feof($handle))
           {
                $data = explode(",",fgets($handle));
                echo $similar_acc[$inc]."\n";
                /*
               if($data[5] == similar_acc[$inc])
                   do something;
                */
            }
            rewind($handle);
    }
             fclose($handle);
    ?>
    output
    o
    data[0]
    data[0]
    data[0]
    1
    data[1]
    data[1]
    data[1[]
    2
    3

    Is it possible or not??
    Last edited by vivien; 05-09-2011 at 12:46 AM.

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
  •