fnmatch

(PHP 4 >= 4.3.0, PHP 5)

fnmatch -- 用模式符合檔案名

說明

bool fnmatch ( string pattern, string string [, int flags] )

fnmatch() 檢查傳入的 string 是否符合給出的 shell 統配符 pattern

此函數對於檔案名尤其有用,但也可以用於普通的字串。普通會員可能習慣於 shell 模式或是至少其中最簡單的形式 '?''*' 通配符,因此使用 fnmatch() 來代替 ereg() 或是 preg_match() 來進行前端搜尋表達式輸入對於非程式員會員更加方便。

例子 1. 用 shell 中的通配符模式符合來檢查彩色

<?php
if (fnmatch("*gr[ae]y"$color)) {
  echo 
"some form of gray ...";
}
?>

警示

目前該函數無法在 Windows 或其它非 POSIX 相容的系統上使用。

參見 glob()ereg()preg_match() 和 Unix 中 fnmatch(3) 的手冊中的標誌名(只要本文件中還未內含它們)。