Jump to: navigation, search

Php fnmatch

From w3cyberlearnings

Contents

PHP function fnmatch

This function matches a file name or string against a user define pattern.

Syntax fnmatch

  • pattern: user define pattern
  • string: string or file to check
  • flags (optional): flag can be combined by using the OR or | operator.
    • 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.
    • FNM_CASEFOLD Caseless match. Part of the GNU extension.
fnmatch(pattern, string, flags);

Example 1

<?php

$txt = "girl";
if (fnmatch("gi*", $txt)) {
	echo "match ...";
}
else {
	echo 'not match..';
}
?> 

Example 2

<?php

$files = array(
	 'index.php',
	 'about.php',
	 'lost.php',
	 'file.txt',
	 'great.perl');

foreach ($files as $file) {
	if (fnmatch('*.php', $file)) {
		echo $file . '</br>';
	}
}
?> 

Output

index.php
about.php
lost.php

Related Links


basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--

Navigation
Web
SQL
MISC
References