2
votes

According to standards specified here: http://en.wikipedia.org/wiki/Comma-separated_values

and a CSV file generated from MS Excel, I wonder how can we import CSV file in php in this case:

  • normally, CSV cells are not enclosed in double quotes ("), but will be enclosed when there is a comma (,), double quote (") or new line character (\n) in cell value.

  • double quotes in cell are replaced with twice double quotes (" => "").

  • e.g. testCell 1,"test,comma cell 2","testCell ""double quote"" 3",testCell 4

Now, the issue is, how can we identify/separate each cell while reading such CSV as the cells may be enclosed with double quote or may not be.

1
@outis I don't know about that. Excel usually outputs CSV that's nonstandard compliant. fgetcsv doesn't like it one bit. - Phoenix
@Phoenix: maybe, but fgetcsv works with both the specific case described and the test data. - outis

1 Answers

0
votes

@outis: you were right (fgetcsv works with both the specific cases). Issue was with parsing some German characters before applying fgetcsv.