: This article describes how to use glob to traverse all files in a folder. For more information about PHP tutorials, see. You can use opendir and readdir to traverse all files in a folder.
Example: Find all php files in the specified directory (do not search for subfolders). The code is as follows:
For example, you can use the glob method to traverse the code.
Note that glob returns path + search result path, for example, path = '/home/fdipzone '.
Array( [0] => /home/fdipzone/a.php [1] => /home/fdipzone/b.php [2] => /home/fdipzone/c.php)
This is different from the result returned by opendir and readdir.
If you only want to traverse the current directory. You can change it to glob ('*. php ');
Glob syntax description:
array glob ( string $pattern [, int$flags = 0 ] )
The glob () function searches for all file paths that match the pattern according to the rules used by the libc glob () function, similar to the rules used by General shells. Do not perform abbreviation extension or parameter substitution. Glob uses the regular expression matching path.
Valid flags include:
GLOB_MARK-add a diagonal line to each returned item
GLOB_NOSORT-returns (unordered) files in the original order in the directory)
GLOB_NOCHECK-returns the search mode if no matching file exists.
GLOB_NOESCAPE
GLOB_BRACE-extended {a, B, c} to match 'A', 'B' or 'C'
GLOB_ONLYDIR-returns only Directory items that match the pattern.
GLOB_ERR-stop and read error messages (such as unreadable directories). all errors are ignored by default.
Example: use glob to traverse all php files in a specified folder (including subfolders)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes how to use the glob method to traverse all the files in the folder, including the content, and hope to help friends who are interested in PHP tutorials.