누구나이 문제를 해결할 수 있습니다.경로를 캡처하는 정규식 변수를 만드는 방법
example $uri = '/username/carlos'; => $routes[] = '/username/@name';
는 "카를로스"
$routes[] = '/list/edit/@id:[0-9]{3}';
$routes[] = '/username/@name';
$routes[] = '/archive/*';
$routes[] = '/';
$uri = '/username/carlos';
foreach ($routes as $pattern)
{
if (preg_match('#^' . preg_replace('#(?:{{)[email protected](\w+\b)(?:}})?#i', '(?P<\1>[\w\-\.!~\*\'"(),\s]+)',
str_replace('\*', '(.*)', preg_quote($pattern, '/'))) . '\/?$#i', $uri, $matchs))
{
//how to make regex for this to work :
echo $name; // carlos =>$uri = '/username/carlos'; or matt => $uri = '/username/matt';
}
}
덕분에 당신이 작동하도록하기 위해 수행해야 할 것입니다 더 많은 일이있다
왜 readymade 라우팅 프레임 워크를 사용하지 않습니까? 그리고 중첩 된 패턴 변환 부분을 먼저 디버그하여 디버깅하지 않아야합니까? – mario