Azr*_*mil 3 php string compare
如何比较这个字符串:
commodity/search/oil/branch/index
Run Code Online (Sandbox Code Playgroud)
有了这个 :
commodity/search/*/branch/index
Run Code Online (Sandbox Code Playgroud)
它应该返回true,尽管"oil"被替换为其他词.
$match = preg_match("/commodity\/search\/(.*)\/branch\/index/", "commodity/search/someotherword/branch/index");
Run Code Online (Sandbox Code Playgroud)
$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");
Run Code Online (Sandbox Code Playgroud)
这只会匹配大写和小写的az字符,数字,连字符和下划线.根据需要调整.