fgetcsv skip blank lines in file

前端 未结 3 867
小鲜肉
小鲜肉 2021-01-04 09:26

I have this script that I did, it basically grabs all the files in my \"logs\" folder and merge them all in one array file, my only problem is that, sometimes the script bre

3条回答
  •  迷失自我
    2021-01-04 10:06

    In short

    $csv = array_map('str_getcsv', file($file_path, FILE_SKIP_EMPTY_LINES));
    

    Explanation

    1. file reads the content of the file into an array. The FILE_SKIP_EMPTY_LINES will skip the empty lines in the file.
    2. array_map will apply the function str_getcsv on each element of the array. str_getcsv will parse the string input for fields in csv format and return an array containing the fields.

    Read more about str_getcsv

    Read more about file

    Read more about array_map

提交回复
热议问题