Home > Article > Backend Development > php fnmatch file name matching pattern_PHP tutorial
php fnmatch file name matching pattern
fnmatch
(PHP 4" = 4.3.0, PHP 5)
fnmatch - Match pattern
on a filename
Description
boolean fnmatch(string$pattern, string$string[abstract$flag=0])
fnmatch() checks if a given shell wildcard pattern will be matched by a string.
Parameters
Pattern
Wildcard pattern in shell.
String
Test string. This function is particularly useful for filenames, but can also be used for ordinary strings.
The average user can use Shell mode, or at least in its simplest form, to '? ' and ' * ' wildcards so using fnmatch() instead of preg_match() as the front-end input search expression may be more convenient for non-programming users.
Flag
A FNM_XXX constant.
Return value
Returns TRUE if there is a match, false otherwise.
Modify
Release Notes
5.3.0 This feature is now available on Windows platforms.
Example
Example #1 Check color names against a shell wildcard pattern
if (fnmatch("*gr[ae]y", $color)) {
echo "some form of gray ...";
}
?>