2

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.

3
  • possible duplicate of parse csv file php, How to parse csv in PHP having multiline data in a column Commented Dec 26, 2011 at 7:35
  • @outis I don't know about that. Excel usually outputs CSV that's nonstandard compliant. fgetcsv doesn't like it one bit. Commented Dec 26, 2011 at 7:37
  • 1
    @Phoenix: maybe, but fgetcsv works with both the specific case described and the test data. Commented Dec 26, 2011 at 7:41

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.