fnmatch() 函数是 PHP 的内置函数,用于进行模式匹配。它使用 shell 风格的模式来匹配字符串。
函数原型:
fnmatch(string $pattern, string $string, int $flags = 0): bool
参数说明:
$pattern
:要匹配的模式,支持通配符 *
和 ?
。$string
:要进行匹配的字符串。$flags
:可选参数,用于指定匹配模式的标志。可以是以下常量的组合:FNM_NOESCAPE
:禁用反斜杠转义。FNM_PATHNAME
:斜杠字符 /
将不会匹配通配符 *
和 ?
。FNM_PERIOD
:通配符 *
和 ?
将不会匹配以 .
开头的文件名。FNM_CASEFOLD
:不区分大小写匹配。返回值:
示例:
$pattern = "*.txt";
$string = "file.txt";
if (fnmatch($pattern, $string)) {
echo "Pattern matches the string";
} else {
echo "Pattern does not match the string";
}
输出结果:
Pattern matches the string
上一篇:php怎么实现intval函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站