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()
來進行前端搜索表達式輸入對於非程序員用戶更加方便。