Search code examples
phpexcelcsvcsv-import

php CSV import generated from MS Excel


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.


Solution

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