- preg_match: documentation ( source)
- preg_replace: documentation ( source)
<?php
$uri = 'administrator/clients/client/11'; // function input
$routes = array(
'administrator/clients' => 'administrator/clients',
'administrator/client/(:num)' => 'administrator/clients/client/$1',
);
foreach ($routes as $route => $controller) {
$key = preg_replace('#[$][0-9]+#', '([^/]+)', $controller); // Converter alle $1, $2 osv til "hvad som helts")
if (preg_match('#^' . $key . '$#', $uri, $match)) {
$route;
// $uri skal altså ligne "administrator/client/11"
}
}