4

如何使用 fgetcsv() 重置文件指针?

我有下面的循环,嵌套在另一个while循环中。但是,它从断点开始读取 CSV,而不是在第一次运行后开始读取。

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;
        }
}
4

3 回答 3

13

您可以使用rewind()fseek()来执行此操作:

rewind($fp2);
// ...is the same as:
fseek($fp2, 0);
于 2012-02-28T14:10:44.530 回答
2

rewind()

于 2012-02-28T14:09:03.423 回答
1

继续是最好的解决方案....试试这个

 continue 2 ;
于 2012-02-28T14:14:44.390 回答