PHP - glob
Trieda
Metóda - glob
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
The glob() function searches all files and directories matching
a pattern by rules of the glob() function of the libc library. The
rules are similar to rules in common shells.
Please note: The function works only in the filesystem of the given server and therefore there's no way to search for files of remote sources.
Please note: The function is not available on some systems, such as old Sun OS.
Please note: Tthe GLOB_BRACE flag is not
available on some non-GNU systems, such as Solaris.
Procedurálne
- function glob (string $pattern, int $flags = 0) : array
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $pattern | string | The pattern for searching, on which no tilde expansion nor parameter substitution is applied. | |
| $flags | int | 0 | Accepts flags: GLOB_MARK - To each returned directory a slash is added. GLOB_NOSORT - The returned files are not sorted and are in the order as found. If this flag is not used, the files and directories are sorted alphabetically. GLOB_NOCHECK - If no matching files or directories are found, the pattern is returned.
|
Mávratovej hodnoty
Vracia: array
Returns an array with files or directories matching the pattern. Returns an
empty array if nothing matches or false if an error occured.
Príklady
This example finds all files and directories which matches the patten *.json.
<?php
foreach (glob("*.json") as $file) {
echo "Found a file '$file'";
}
