Example
Checking a color name against a shell wildcard pattern:
html
<?php
$txt = "My car is a dark color";
if (fnmatch("*col[ou]r",$txt))
{
echo "hmm...";
}
?>
Definition and Usage
The fnmatch() function checks if a string or filename matches the given shell wildcard pattern.
Note: This function is not available on non-POSIX compliant systems, except Windows.
Syntax
text
fnmatch(pattern, string, flags)
Parameter Values
| 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 |
Technical Details
| Return Value: | TRUE on success, FALSE on failure |
|---|---|
| PHP Version: | 4.3+ |