PHP skip lines while reading

前端 未结 3 888
面向向阳花
面向向阳花 2021-01-22 15:58

I am trying to find a quick way of reading from a csv file, by first skipping a number of lines, reading about 20 lines, then stopping the read. the only solution right now is u

3条回答
  •  半阙折子戏
    2021-01-22 16:28

    Let's say if you have this piece of code below

    ";    // OPEN ROW
                    if(strpos($data[$c], 'Finished') !== false) {
                        $c++;
                        echo "" . $data[$c] . ""; 
                    }else{
                        echo "" .  $data[$c] . "";
                    }
                    echo "";    // CLOSE ROW
                }
            }
            fclose($handle);
        }
    ?>
    

    if you add

        if($row == 20){ $row++; continue; }
    

    after the while loop

        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
           if($row == 20){ $row++; continue; }
    

    now, let's say if you want to start from row 20, it would continue reading

    let's take another example. if you want to stop reading at line 40 starting from 1 you can insert

       if($row == 40){ $row++; exit; }
    

提交回复
热议问题