PHP/file/glob: Difference between revisions
from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
No edit summary |
link update |
||
| Line 15: | Line 15: | ||
php > echo "MATCH: [".fnmatch('/*test/*','/sometest/somethong')."]\n"; | php > echo "MATCH: [".fnmatch('/*test/*','/sometest/somethong')."]\n"; | ||
MATCH: [1] | MATCH: [1] | ||
* [ | * [[PHP/fx/glob|{{fmt/code|glob()}}]] accepts a [[filespec]] that includes a [[file mask]], and returns a list of matching [[filespec]]s. | ||
** A file mask in this context can be e.g. {{fmt/code|*.php}} or {{fmt/code|/home/woozle/*.php}} but not {{fmt/code|~/*.php}}. | ** A file mask in this context can be e.g. {{fmt/code|*.php}} or {{fmt/code|/home/woozle/*.php}} but not {{fmt/code|~/*.php}}. | ||
** The {{fmt/code|*}} and {{fmt/code|?}} wildcards are both recognized. | ** The {{fmt/code|*}} and {{fmt/code|?}} wildcards are both recognized. | ||
** The mask may include multiple wildcards, for folders as well as files. | ** The mask may include multiple wildcards, for folders as well as files. | ||
*** '''Example''': {{fmt/code|/b*/b*}} will return all files beginning with b inside root-level folders beginning with b. | *** '''Example''': {{fmt/code|/b*/b*}} will return all files beginning with b inside root-level folders beginning with b. | ||
Latest revision as of 01:52, 9 May 2026
About
PHP can do glob-based directory listings and can also check a given filename string against a given glob string.
See also: globbing
Functions
- Template:Fmt/code reports whether the given filespec string matches the given wildcard string
- Note that this does appear to work as expected for filespecs (not just filenames):
php > echo "MATCH: [".fnmatch('/*test/*thing','/sometest/something')."]\n";
MATCH: [1]
php > echo "MATCH: [".fnmatch('/*test/*thing','/sometest/somethong')."]\n";
MATCH: []
php > echo "MATCH: [".fnmatch('/*test/','/sometest/somethong')."]\n";
MATCH: []
php > echo "MATCH: [".fnmatch('/*test/*','/sometest/somethong')."]\n";
MATCH: [1]
- [[PHP/fx/glob|Template:Fmt/code]] accepts a filespec that includes a file mask, and returns a list of matching filespecs.
- A file mask in this context can be e.g. Template:Fmt/code or Template:Fmt/code but not Template:Fmt/code.
- The Template:Fmt/code and Template:Fmt/code wildcards are both recognized.
- The mask may include multiple wildcards, for folders as well as files.
- Example: Template:Fmt/code will return all files beginning with b inside root-level folders beginning with b.
