HOWTO比较字符串:比较路径字符串通配符在PHP
commodity/search/oil/branch/index
与此:
commodity/search/*/branch/index
虽然 “油” 是与其他字代替它应该返回true。
HOWTO比较字符串:比较路径字符串通配符在PHP
commodity/search/oil/branch/index
与此:
commodity/search/*/branch/index
虽然 “油” 是与其他字代替它应该返回true。
$match = preg_match("/commodity\/search\/(.*)\/branch\/index/", "commodity/search/someotherword/branch/index");
$match
将是真实的(或一些值评估为真,如1)如果发现匹配。
注:以上将匹配任何额外的路径上,如commodity/search/some/other/word/branch/index
如果你只是想一个单词,而不是类似的路径结构,那么你可以尝试这样的事:
$match = preg_match("/commodity\/search\/[A-Za-z0-9_-]+\/branch\/index/", "commodity/search/some-OTHER_word/branch/index");
这只会匹配大写和小写az字符,数字,连字符和下划线。根据需要调整。
一些正则表达式呢? – mauris 2012-07-21 16:00:33
试试用/替换逗号http://stackoverflow.com/questions/9692914/difference-between-two-strings – Cups 2012-07-21 16:42:42