PHP.nl

fnmatch

fnmatch

Match filename against a pattern

bool **fnmatch** string $pattern string $filename int $flags
checks if the passed  would

match the given shell wildcard . fnmatch``filename``pattern

pattern The to match against. Usually, the will contain wildcards like and .

  `pattern``pattern``'?'``'*'`

filenameThe tested string. This function is especially useful for filenames, but may also be used on regular strings.

   The average user may be used to shell patterns or at least in their
   simplest form to  and 
   wildcards so using  instead of
    for
   frontend search expression input may be way more convenient for
   non-programming users.
  `'?'``'*'``fnmatch``preg_match`

flags The value of can be any combination of the following flags, joined with the .

  `flags`binary OR (|) operator

Returns true if there is a match, false otherwise.

Voorbeeld: Checking a color name against a shell wildcard pattern

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

Waarschuwing: > For now, this function is not available on non-POSIX compliant systems except Windows.

glob``preg_match``sscanf``printf``sprintf