All pastes #611263 Raw Edit

k4st

public php v1 · immutable
·published 2007-07-09 20:55 UTC
rendered paste body
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<type>[a-z]+)\)(?P<var>[^/]*)~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();