PHP fnmatch() 函數


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊

定義和用法

fnmatch() 函數根據指定的模式來匹配檔案名或字串。

語法

fnmatch(pattern,string,flags)

參數 描述
pattern 必需。規定要檢索的模式。
string 必需。規定要檢查的字串或檔。
flags 可選。


提示和注釋

注釋:該函數無法在 Windows 平臺上使用。


實例

根據 shell 通配符模式來檢查顏色名:

<?php
$txt = "My car is darkgrey..."
if (fnmatch("*gr[ae]y",$txt))
{
echo "some form of gray ...";
}
?>


PHP Filesystem 參考手冊 完整的 PHP Filesystem 參考手冊