fnmatch() function in PHP



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

Syntax

fnmatch(pattern, string, flags)

Parameters

  • pattern − The pattern to search.

  • string − The string to test.

  • flags − Any of the following values:

    • FNM_NOESCAPE − Disable backslash escaping

    • FNM_PATHNAME − Slash in string only matches slash in the given pattern.

    • FNM_PERIOD − Leading period in string must be exactly matched by period in the given pattern.

Return

The fnmatch() function returns TRUE if it is a match, else FALSE.

The following is an example showing wildcard pattern.

Example

 Live Demo

<?php
   $file = "organization.txt";
   if (fnmatch("*organi[zs]ation",$file)) {
      echo "Found!";
   } else {
      echo "Not found!";
   }
?>

Output

Not found!
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements