Kirby Kirby - 10 months ago 59
PHP Question

Is there any path function in PHP for matching path mask?

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

Let's say we have the path




will be matched.

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

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.


Yes there is, it's called fnmatch()

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