I have a string of this-
$str = "field1.id as field1,
DATE_SUB(field2, INTERVAL (DAYOFMONTH(field2)-1) DAY) as field2,
field3.name as field3";
Need to explode
this into array with ,
as this:
$requiredArray = array(
0 => field1.id as field1,
1 => DATE_SUB(field2, INTERVAL (DAYOFMONTH(field2)-1) DAY) as field2
2 => field3.name as field3
);
I've tried with explode but it doesn't works:
$requiredArray = explode(', ', $str);
// doesn't work as "DATE_SUB(field2, INTERVAL ..." also gets exploded
Any trick/ideas?
preg_match_all('#\(.*?\)|[^,]+#', $str, $matches); var_dump($matches[0]);
– Shahexplode("\n", $str)
? By line break, not by comma. – Janise