Log in

View Full Version : question if I can rewind feof function for every loop



vivien
05-06-2011, 07:30 AM
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.
:) :confused:
Here's the code below:



$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??