嘿我的路由脚本是不是与特殊的字符工作,我没有任何想法了解为什么或如何解决它。Php preg_match不能使用?
我的网址:/test/x/hállò/123
我的路由器加入URL:/测试/:VARx前提/:variableZ/123
$route['url'] ="/test/x/:name/123";
$reqMet = $_SERVER['REQUEST_METHOD'];
$route['method'] = "GET";
$reqUrl = "/test/x/hállò/123";
$matches = Array();
$pattern = "@^" . preg_replace('/\\\:[a-zA-Z0-9\_\-]+/', '([a-zA-Z0-9\-\_]+)', preg_quote($route['url'])) . "[email protected]";
if($reqMet == $route['method'] && preg_match($pattern, $reqUrl, $matches)) {
echo "THIS SHOULD BE THE OUTPUT";
}
因此,它不能与像LOL或干草字工作,但我回来了正确的网址,但像文章/测试/ 123的东西都是完美的。
希望有人为我解决问题。 感谢
编辑
所以这是工作
$router->addRoute('GET','/test/x/hállò/123','home/main',false);
URL >>http://localhost/test/x/hállò/123
但这不
$router->addRoute('GET','/test/x/:name/123','home/main',false`);
URL >>http://localhost/test/x/hállò/123
:名称是可替换的,像文章ID或其他任何变量。
的[我怎么能预浸\可能的复制_replace特殊字符,如'Prêt-à-porter'?](http://stackoverflow.com/questions/2050723/how-can-i-preg-replace-special-character-like-pr%c3%aat-%c3 %a0-porter)以及[preg_match an d(非英文)拉丁字符](http://stackoverflow.com/questions/5424494/preg-match-and-non-english-latin-characters) – Jer
@ chris85是的但你应该得到:S我想得到it – Juan
@ C0dekid nah它没有解决我的问题 – Juan