function parse_routes() { $route = '/action/(int)a/(str)b'; $path = '/action/100/moo'; $vars = array(); $path = preg_split("~/~", $path, -1, PREG_SPLIT_NO_EMPTY); preg_match_all("~\((?P[a-z]+)\)(?P[^/]*)~i", $route, $matches, PREG_SET_ORDER); $i = 1; foreach($matches as $match) { if(isset($match['type']) && $match['type'] != '') { $fn = $match['type'] .'val'; $vars[$match['var']] = $fn($path[$i]); } $i++; } print_r($vars); } parse_routes();