PHP fnmatch() Function

PHP fnmatch Function


Definition :

The PHP fnmatch() function is used to check if a filename or string matches against a specified shell wildcard pattern. The function returns true if there is a match, false otherwise.

Syntax

  fnmatch(patternstringflags)

Parameter
Parameter Description
pattern Required. Specifies the shell wildcard pattern
string Required. Specifies the string or file to check
flags Optional. Can be one or a combination of the following:
  • FNM_NOESCAPE - Disable backslash escaping
  • FNM_PATHNAME - Slash in string only matches slash in the given pattern
  • FNM_PERIOD - Leading period in string must be exactly matched by period in pattern
  • FNM_CASEFOLD - Caseless match. Part of the GNU extension

Example: checking a shell wildcard pattern in a string

The example below shows the usage of fnmatch() function.

Output : Match found