dqb77047 2016-09-10 19:00
浏览 46
已采纳

PHP中是否有路径功能用于匹配路径掩码?

I'm looking for a native solution for path mask matching like in console.

Let's say we have the path /path/to/some_filename.txt Mask

/path/*/some?file*.txt

will be matched.

var_dump(test_path('/path/to/some_filename.txt', '/path/*/some?file*.txt'));
//true

It should work with a string only, but not using real files.

Yes, it can be converted into a regular expression, I have my own code, but I would like to use completely the same like in console.

  • 写回答

1条回答 默认 最新

  • duanlongling5308 2016-09-10 19:25
    关注

    Yes there is, it's called fnmatch()

    var_dump(fnmatch('/path/*/some?file*.txt', '/path/to/some_filename.txt'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?