Menu Samaritan's Purse

FNMATCH

Match filename against a pattern

SYNTAX

fnmatch ( string $pattern , string $string [, int $flags = 0 ] ) : bool

PARAMETERS

pattern

The shell wildcard pattern.

string

The tested string. This function is especially useful for filenames, but may also be used on regular strings.

The average user may be used to shell patterns or at least in their simplest form to '?' and '*' wildcards so using fnmatch() instead of preg_match() for frontend search expression input may be way more convenient for non-programming users.

flags

The value of flags can be any combination of the following flags, joined with the binary OR (|) operator.

NUMBER NAME DESCRIPTION
1 FNM_PATHNAME Slash in string only matches slash in the given pattern.
2 FNM_NOESCAPE Disable backslash escaping.
4 FNM_PERIOD Leading period in string must be exactly matched by period in the given pattern.
16 FNM_CASEFOLD Caseless match. Part of the GNU extension.

RETURN

Returns TRUE if there is a match, FALSE otherwise.

EXAMPLES

PATTERN STRING

true

FLAGS | FNM_PATHNAME

bool(true)
bool(false)

FLAGS | FNM_NOESCAPE

bool(true)
bool(false)

FLAGS | FNM_PERIOD

bool(true)
bool(false)

FLAGS | FNM_CASEFOLD

bool(false)
bool(true)

PHP