我有一串这个 -
$str = "field1.id as field1,
DATE_SUB(field2, INTERVAL (DAYOFMONTH(field2)-1) DAY) as field2,
field3.name as field3";
需要explode
将,
与$requiredArray = array(
0 => field1.id as field1,
1 => DATE_SUB(field2, INTERVAL (DAYOFMONTH(field2)-1) DAY) as field2
2 => field3.name as field3
);
格式化为数组:
$requiredArray = explode(', ', $str);
// doesn't work as "DATE_SUB(field2, INTERVAL ..." also gets exploded
我尝试过爆炸,但它不起作用:
{{1}}
任何技巧/想法?
答案 0 :(得分:-1)
试试这个:
preg_match_all('~(.*)[^(],?~', $str, $matches);