Current Location: Home> Function Categories> fnmatch

fnmatch

Match file names with pattern
Name:fnmatch
Category:File system
Programming Language:php
One-line Description:Match file names or strings according to the specified pattern.

Definition and usage

The fnmatch() function matches file names or strings based on the specified pattern.

Example

Check the color name according to the shell wildcard:

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

grammar

 fnmatch ( pattern , string , flags )
parameter describe
pattern Required. Specify the mode to be retrieved.
string Required. Specifies the string or file to be checked.
flags Optional.

illustrate

This function is especially useful for file names, but can also be used for normal strings. Ordinary users may be accustomed to shell mode or at least the simplest forms of '?' and '*' wildcards, so using fnmatch() instead of ereg() or preg_match() for front-end search expression input is more convenient for non-programmer users.

Similar Functions
Popular Articles