Definition and usage
The Glob () function returns the file name or directory that matches the specified pattern.
The function returns an array that contains a matching file/directory. Returns False if an error occurs.
Parameters |
Description |
File |
Necessary. Specifies the retrieval mode. |
Size |
Optional. Specify a special setting.
- Glob_mark-Add a slash to each returned item
- Glob_nosort-Returns (not sorted) according to the original order in which the files appear in the directory
- Glob_nocheck-Returns the mode used for search if no file matches
- Glob_noescape-Backslash does not escape meta-characters
- Glob_brace-expand {a,b,c} to match ' A ', ' B ' or ' C '
- Glob_onlydir-Returns only catalog entries that match the pattern
- Glob_err-Stop and read error messages (such as unreadable directories), ignoring all errors by default
Note: Glob_err is added in PHP 5.1. |
Print_r (glob("*.txt")); Print_r (glob("* *"));
Output: Array ([0] = a.txt [1] = b.txt)
1. Get all the files with the suffix PHP (plus the path)
$file=glob(' d:/web/tcpdf/*.php '); Print_r ($file); // If you do not specify a folder, you are displaying a file with the same sibling directory suffix PHP. Return as an array
Output: Array ([0] = d:/web/tcpdf/tcpdf.php [1] = d:/web/tcpdf/tcpdf_autoconfig.php [2] = = D:/web/tcpdf/tcpdf_ barcodes_1d.php [3] = d:/web/tcpdf/tcpdf_barcodes_2d.php [4] = d:/web/tcpdf/tcpdf_import.php [5] = D:/web/ tcpdf/tcpdf_parser.php)
2. Get all the files with the suffix PHP and HTML (plus the path)
$file=glob(' d:/phpstudy/www/prictue/*.{ jpg,html} ',glob_brace); Var_dump ($file);
PHP using Glob () to find file tips