PHP glob() Function

The glob() function returns an array of filenames or directories matching a specified pattern.This function returns an array of files/directories, or FALSE on failure.

array glob ( string $pattern [, int $flags = 0 ] )

The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.

Example -

The above example will output something similar to:

funclist.txt size 44686
funcsummary.txt size 267625
quickref.txt size 137820

ParameterDescription
patternRequired. Specifies the pattern to search for
flagsOptional. Specifies special settings.
Possible values : -
  • GLOB_MARK - Adds a slash to each item returned
  • GLOB_NOSORT - Return files as they appear in the directory (unsorted)
  • GLOB_NOCHECK - Returns the search pattern if no match were found
  • GLOB_NOESCAPE - Backslashes do not quote metacharacters
  • GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'
  • GLOB_ONLYDIR - Return only directories which match the pattern
  • GLOB_ERR - (added in PHP 5.1) Stop on errors (errors are ignored by default)