Assuming you have a string as follows:
$str = 'one value, two value, "three, cool value", four value';
How would you make it an array as follows:
$arr = array('one value', 'two value', 'three, cool value', 'four value');
(That's all about CSV and values that contain a comma and thus are double quoted.)
If you are really parsing it from a string, use str_getcsv.
If you are reading data from a file, use fgetcsv.
You can use str_getcsv
$str = 'one value, two value, "three, cool value", four value';
var_dump(str_getcsv($str));
Results:
array(4) {
[0]=>
string(9) "one value"
[1]=>
string(9) "two value"
[2]=>
string(17) "three, cool value"
[3]=>
string(10) "four value"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With