NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - glob

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$patternstring

The pattern for searching, on which no tilde expansion nor parameter substitution is applied.

$flagsint 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.

  • GLOB_NOESCAPE - Backslashes don't escape special characters.
  • GLOB_BRACE - Sequences like {a, b, c} will be expanded to match "a", "b" or "c".
  • GLOB_ONLYDIR - Returns matching directories only.
  • GLOB_ERR - Stops the searching on errors (e.g. caused by unreadable files or directories). Errors are ignored without this flag.

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'";
}

Súvisiace manuály

        Aktivity