PHP 中的 fnmatch() 函数
phpprogrammingserver side programming更新于 2025/5/15 15:52:17
fnmatch() 函数将文件名或字符串与指定模式进行匹配。
语法
fnmatch(pattern, string, flags)
参数
pattern − 要搜索的模式。
string − 要测试的字符串。
flags − 以下任意值:
FNM_NOESCAPE − 禁用反斜杠转义
FNM_PATHNAME − 字符串中的斜杠仅匹配给定模式中的斜线。
FNM_PERIOD − 字符串中的前导句点必须与给定模式中的句点完全匹配。
返回
如果匹配,则 fnmatch() 函数返回 TRUE,否则返回 FALSE。
以下是显示通配符模式的示例。
示例
<?php
$file = "organization.txt";
if (fnmatch("*organi[zs]ation",$file)) {
echo "Found!";
} else {
echo "Not found!";
}
?>
输出
Not found!

