我想要做的是自动匹配URI,并为它们分配正确的描述。可以说,我有如下的URI:用星号匹配URI
test
something/action
controller/test
controller/another
controller/action/something
action
action/test
controller/another/somethingelse
他们真的是随机的,但现在我想用下面的数组(数组,因为我认为这将是最好的解决方案),与它们匹配:
$config = array(
'test' => 'The description of test',
'something/action' => 'Some action description',
'controller/another' => 'Another description',
'controller/action/*' => 'This should match the `controller/action/blah` and everything similar like: `controller/action/something` and give this description'
'action' => 'Action description',
'action/*' => 'As the 2nd above, this should match the `action/test` itself, and similar like `action/anothertest` URI
);
这将是容易的,在没有星号的情况下......(简单$config[$uri]
相匹配的描述),但我想匹配的星号,以及...所以,如果有一个像controller/another/name
控制器和我会使用像controller/another/*
这样的配置,它将匹配这个数组密钥的描述。
任何人有怎么可能做的想法?我基本上需要想法,但欢迎任何其他答案!
这就是聪明! Did not知道'fnmatch'函数,这真棒。谢谢 :) – Lucas