CSVs without quotes not working with fgetcsv

后端 未结 2 800
栀梦
栀梦 2020-12-09 11:55

I\'m trying to parse CSV files uploaded by the user through PHP, but it\'s not working properly.

I\'ve uploaded several properly formatted CSVs and it worked fine, h

2条回答
  •  执笔经年
    2020-12-09 12:04

    Looking at the manual page of fgetcsv, its prototype looks like this :

    array fgetcsv  ( resource $handle  [, int $length  
        [, string $delimiter = ','  [, string $enclosure = '"' 
        [, string $escape = '\\'  ]]]] )
    

    The default value for $enclosure (i.e. the 4th parameter) is a double-quote.

    What if you try specifying that you don't want any enclosure, specifying an empty string for that 4th parameter ?

    (Of course, this might break what's now working -- which means you'd have to deal with two separate cases : files with fields enclosed in double-quotes, and files that couldn't be read by the first case)

提交回复
热议问题