<?php function rSplitReverse($string) { preg_match_all("/\(((?:(?>[^()]+)|(?R))*)\)/", $string, $matches); foreach ($matches[1] as &$m) { if (preg_match_all("/(\((?:(?>[^()]+)|(?R))*\))|[^(),]+/", $m, $items, PREG_SET_ORDER)) { $first = array_shift($items)[0]; foreach ($items as &$item) { $item = isset($item[1]) ? rSplitReverse($item[0]) : $item[0]; } $m = "$first," . implode(',', array_reverse($items)); } } return '(' . implode('),(', array_reverse($matches[1])) . ')'; } echo rSplitReverse('(X,1,1,3),(X,1,1,3),(X,@2,@2,@2,@2,@2,(Y,1))');
You have javascript disabled. You will not be able to edit any code.