在php中爆炸一个字符串,不包括','在括号内

时间:2016-05-12 10:15:23

标签: php arrays explode

我有一串这个 -

$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}}

任何技巧/想法?

1 个答案:

答案 0 :(得分:-1)

试试这个:

preg_match_all('~(.*)[^(],?~', $str, $matches);