If the string is a little more complicated (i.e. the elements may be in quotation marks, and both the delimiter and the quotation mark symbol may appear inside the element), you may also be interested in fgetcsv () and str_getcsv ()
$variable = '"left,right","middle", "up,down"';
$row = str_getcsv($variable);
var_dump($row);
prints
array(3) {
[0]=>
string(10) "left,right"
[1]=>
string(6) "middle"
[2]=>
string(7) "up,down"
}
source
share