Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - fgetcsv() reset pointer

Tags:

php

fgetcsv

How do I reset the file pointer with fgetcsv()?

I have the loop below, nested inside another while loop. However it starts reading the CSV from the break point rather than the beginning after first run.

while($line2 = fgetcsv($fp2, $length2, $fildDelineate2)) {
        if($line[0] == $line2[0]) {
            $desc = addslashes(strip_tags($line2[6]));
            $import2 = "insert into $table2 values('$id','1',\"$line[1]\",'$desc','','0')";
            mysql_query($import2) or die('import2 '.mysql_error());
            $count++;
            break;
        }
}
like image 468
logic-unit Avatar asked Dec 05 '22 17:12

logic-unit


1 Answers

You can use rewind() or fseek() to do this:

rewind($fp2);
// ...is the same as:
fseek($fp2, 0);
like image 141
FtDRbwLXw6 Avatar answered Dec 10 '22 10:12

FtDRbwLXw6