Separation of fields in array

2

I have a string that consists of (included quotation marks):

"campo","outrocampo","maisumcampo"

I need to separate these fields, without the quotation marks, into an array.

What I'm doing is a

 $string = str_replace('"', NULL, $string)

and then a

 $array = explode(',', $string);

However, if any of the fields in the original string contain a comma inside the quotation mark, I think I'll have problems. How to avoid this?

    
asked by anonymous 23.05.2014 / 17:03

1 answer

4

How about using a function that was specifically created to read CSV?

$array = str_getcsv($string);

More details: Documentation

    
23.05.2014 / 17:05