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
  • Obtain file permissions fileperms

    fileperms

    Obtainfilepermission
  • Find file paths that match patterns glob

    glob

    Findfilepathsthatmat
  • Get the inode modification time of the file filectime

    filectime

    Gettheinodemodificat
  • Rename a file or directory rename

    rename

    Renameafileordirecto
  • Open a file or URL fopen

    fopen

    OpenafileorURL
  • Returns the normalized absolute path name realpath

    realpath

    Returnsthenormalized
  • Determine whether the given file name is writable is_writable

    is_writable

    Determinewhethertheg
  • alias for fwrite fputs

    fputs

    aliasforfwrite