PHP Tutorial - 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
$txt = "test.txt";
if (fnmatch("*[t]*",$txt)){
  echo "test...";
}
?>

The code above generates the following result.