PHP fnmatch() Function

Definition

The fnmatch() function matches a filename or string against the specified pattern.

This function is not implemented on Windows platforms.

Syntax

PHP fnmatch() Function has the following syntax.

fnmatch(pattern,string,flags)

Parameter

ParameterIs RequiredDescription
patternRequired.Pattern to search for
stringRequired.String or file check
flagsOptional.Option

Return

Returns TRUE if there is a match, FALSE otherwise.

Example

Checking a file name against a shell wildcard pattern:


<?php//from  w  w  w .  ja  va2  s .  com
$txt = "test.txt";
if (fnmatch("*[t]*",$txt)){
  echo "test...";
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions