fnmatch
用模式匹配文件名
fnmatch()
函数根据指定的模式来匹配文件名或字符串。
根据 shell 通配符来检查颜色名:
<?php $txt = "My car is darkgrey..." if (fnmatch("*gr[ae]y",$txt)) { echo "some form of gray ..."; } ?>
fnmatch(pattern,string,flags)
参数 | 描述 |
---|---|
pattern | 必需。规定要检索的模式。 |
string | 必需。规定要检查的字符串或文件。 |
flags | 可选。 |
此函数对于文件名尤其有用,但也可以用于普通的字符串。普通用户可能习惯于 shell 模式或者至少其中最简单的形式 '?' 和 '*' 通配符,因此使用 fnmatch()
来代替 ereg()
或者 preg_match()
来进行前端搜索表达式输入对于非程序员用户更加方便。