Provide back an array of folders or filenames that corresponds to the given pattern:
<?php print_r(glob(“*.txt”)); ?> |
What the code above might produce is:
Array ( [0] => target.txt [1] => source.txt [2] => test.txt [3] => test2.txt ) |
An array of filenames or directories that match a given pattern is returned by the glob() method.
glob(pattern, flags) |
Parameter |
Description |
pattern |
Essential. indicates the pattern to look for. |
flags |
Not required. outlines unique configurations. · GLOB_MARK: Slashes each returned item · GLOB_NOSORT – Returns files in the directory in their unsorted state. · GLOB_NOESCAPE – Backslashes do not quote metacharacters GLOB_BRACE – Expands {a,b,c} to match ‘a’, ‘b’, or ‘c’ · GLOB_ONLYDIR: Only return directories that are in line with the pattern · (Added in PHP 5.1) GLOB_ERR Stop on errors (by default, errors are ignored) |
Return Value: |
An array of the matched files or folders; if the pattern is not met, FALSE |
PHP Version: |
4.3+ |
PHP Changelog: |
PHP 5.1: The flags parameter now includes the GLOB_ERR value. |
Provide back an array of folders or filenames that corresponds to the given pattern:
<?php print_r(glob(“*.*”)); ?> |
What the code above might produce is:
Array ( [0] => contacts.csv [1] => default.php [2] => target.txt [3] => source.txt [4] => tem1.tmp [5] => test.htm [6] => test.ini [7] => test.php [8] => test.txt [9] => test2.txt ) |