我想要做的是自動匹配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