PHP CSV string to array

前端 未结 10 1270
攒了一身酷
攒了一身酷 2020-11-27 02:41

I\'m trying to parse a CSV string to an array in PHP. The CSV string has the following attributes:

Delimiter: ,
Encl         


        
10条回答
  •  情歌与酒
    2020-11-27 03:33

    If you have carriage return/line feeds within columns, str_getcsv will not work.

    Try https://github.com/synappnz/php-csv

    Use:

    include "csv.php";
    $csv = new csv(file_get_contents("filename.csv"));
    $rows = $csv->rows();
    foreach ($rows as $row)
    {
      // do something with $row
    }
    

提交回复
热议问题