PHP fnmatch() Function
In this chapter you will learn:
- Definition for PHP fnmatch() Function
- Syntax for PHP fnmatch() Function
- Parameter for PHP fnmatch() Function
- Return for PHP fnmatch() Function
- Example - Checking a file name against a shell wildcard pattern
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
Parameter | Is Required | Description |
---|---|---|
pattern | Required. | Pattern to search for |
string | Required. | String or file check |
flags | Optional. | Option |
Return
Returns TRUE if there is a match, FALSE otherwise.
Example
Checking a file name against a shell wildcard pattern:
<?php/*from ja va2 s .com*/
$txt = "test.txt";
if (fnmatch("*[t]*",$txt)){
echo "test...";
}
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP fopen() Function
- Syntax for PHP fopen() Function
- Parameter for PHP fopen() Function
- Return for PHP fopen() Function
- Example - Output error message if cannot open a file
- Example - Open Remote Files
Home » PHP Tutorial » PHP File Functions