Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试为我自己的框架创建一个路由器,假设我有一个像这样注册的路由
$f->addRoute("/note/$1/edit/$2", "/note/edit/$1");
这告诉路由器的是,对于给定的字符串,比如/note/2/edit/some/non/sense/url转换为/note/edit/2我该怎么做!?
/note/2/edit/some/non/sense/url
/note/edit/2
我已经为此工作了几个小时,但我找不到任何正则表达式!
我会很感激这里的任何帮助。
preg_replace('|^/note/(\d+)/edit/.*$|', '/note/edit/$1', '/note/2/edit/some/non/sense/url');
基本上,您必须注意以下几点: