PHP reading a csv file effectively

后端 未结 2 2169
走了就别回头了
走了就别回头了 2021-02-10 11:18

There are a few ways to read CSV files with PHP. I used to use the explode function to put each line into an array and then explode commas and use trim

2条回答
  •  半阙折子戏
    2021-02-10 12:24

    There is a function for reading files in line-wise: file(), which also works on both linebreak types.

    And the shortest method to read in the whole CSV file is:

    $data = array_map("str_getcsv", file($filename));
    

    Not sure what your $num = count() was about.

提交回复
热议问题