How do you insert a CSV semicolon string into a value?

"AMZN","Amazon.com, Inc.",211.22,"11/9/2011","4:00pm","-6.77 - -3.11%",4673052 

Amazon.com, Inc. considered as 2 values ​​instead of one.

I tried this $data = explode( ',', $s);

How do I change this to avoid a comma in the value problem?

+4
source share
2 answers

You should probably look at str_getcsv () (or fgetcsv () if you are loading CSV from a file)

This will read the contents of the CSV into an array without the need for an explosion, etc.

Change - expand at the point made by Pekka if you use PHP <5.3 str_getcsv() will not work, but there is an interesting approach here that reproduces functionality for smaller versions. And another approach here that uses fgetcsv() after creating a temporary file.

+8
source

Use the dedicated CSV library. It has been explained over and over again that parsing file formats such as CSV manually pose problems because you do not know all the CSV options and all the rules to do it right.

0
source

Source: https://habr.com/ru/post/1380476/


All Articles