fnmatch

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

fnmatch锟斤拷模式匹锟斤拷锟侥硷拷锟斤拷

说锟斤拷

fnmatch ( string $pattern , string $string [, int $flags = 0 ] ) : bool

fnmatch() 锟斤拷榇拷锟斤拷 string 锟角凤拷匹锟斤拷锟斤拷锟斤拷锟� shell 统锟斤拷锟� pattern锟斤拷

锟斤拷锟斤拷

pattern

shell 统锟斤拷锟斤拷锟�

string

要锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷 锟剿猴拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫o拷锟斤拷也锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷通锟斤拷锟街凤拷锟斤拷锟斤拷

锟斤拷通锟矫伙拷锟斤拷锟斤拷习锟斤拷锟斤拷 shell 模式锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷虻サ锟斤拷锟绞� '?' 锟斤拷 '*' 通锟斤拷锟斤拷锟斤拷锟斤拷使锟斤拷 fnmatch() 锟斤拷锟斤拷锟斤拷 preg_match() 锟斤拷锟斤拷锟斤拷前锟斤拷锟斤拷锟斤拷锟斤拷锟绞斤拷锟斤拷锟斤拷锟节非筹拷锟斤拷员锟矫伙拷锟斤拷锟接凤拷锟姐。

flags

The value of flags can be any combination of the following flags, joined with the binary OR (|) operator.

A list of possible flags for fnmatch()
Flag Description
FNM_NOESCAPE Disable backslash escaping.
FNM_PATHNAME Slash in string only matches slash in the given pattern.
FNM_PERIOD Leading period in string must be exactly matched by period in the given pattern.
FNM_CASEFOLD Caseless match. Part of the GNU extension.

锟斤拷锟斤拷值

匹锟斤拷锟津返伙拷 TRUE锟斤拷锟斤拷锟津返伙拷 FALSE锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
5.3.0 锟剿猴拷锟斤拷锟斤拷始锟斤拷 Windows 平台锟斤拷锟斤拷效锟斤拷

锟斤拷锟斤拷

Example #1 锟斤拷 shell 锟叫碉拷通锟斤拷锟侥J狡ワ拷锟斤拷锟斤拷锟斤拷锟斤拷色锟斤拷锟斤拷

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

注锟斤拷

Warning

目前锟矫猴拷锟斤拷锟睫凤拷锟斤拷 Windows 锟斤拷锟斤拷锟斤拷锟斤拷 POSIX 锟斤拷锟捷碉拷系统锟斤拷使锟矫★拷

锟轿硷拷

  • glob() - 寻锟斤拷锟斤拷模式匹锟斤拷锟斤拷募锟铰凤拷锟�
  • preg_match() - 执锟斤拷匹锟斤拷锟斤拷锟斤拷锟斤拷式
  • sscanf() - 锟斤拷锟斤拷指锟斤拷锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟�
  • printf() - 锟斤拷锟斤拷锟绞斤拷锟斤拷址锟斤拷锟�
  • sprintf() - Return a formatted string