php - How to split text in array by comma if comma is in text value
245
Solution:
Try this
$str = '0, "Some, text", 0.23, 4';
$new = str_getcsv($str, ",","",",");
echo "<pre>";
print_r($new);
Output
Array
(
[0] => 0
[1] => Some, text
[2] => 0.23
[3] => 4
)
For more info aboutstr_getcsv
please read http://php.net/manual/en/function.str-getcsv.php
Answer
Solution:
If you use explode for this, the first impresion is that you will indeed get 5 values instead of 4 as you wish.
Your best option would be to use
str_getcsv
(link). Check this thread.Answer
Solution:
The simplest way is, by using explode:
Will return "str1: Text str2: Some "