Current Location: Home> Function Categories> glob

glob

Find file paths that match patterns
Name:glob
Category:File system
Programming Language:php
One-line Description:Returns an array containing file names/directories that match the specified pattern.

Definition and usage

glob() function returns the file name or directory that matches the specified pattern.

This function returns an array containing matching files/directories. If an error occurs, return false.

Example

Example 1

 <?php
print_r ( glob ( "*.txt" ) ) ;
?>

The output is similar:

 Array
(
[0] => target.txt
[1] => source.txt
[2] => test.txt
[3] => test2.txt
)

Example 2

 <?php
print_r ( glob ( "*.*" ) ) ;
?>

The output is similar:

 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
)

grammar

 glob ( pattern , flags )
parameter describe
file Required. Specify the search mode.
size

Optional. Special settings are specified.

  • GLOB_MARK - Add a slash to each returned item
  • GLOB_NOSORT - Return in the original order in which files appear in the directory (not sorted)
  • GLOB_NOCHECK - Returns the pattern used for search if there is no file match
  • GLOB_NOESCAPE - Backslash does not escape metacharacters
  • GLOB_BRACE - Extended {a,b,c} to match 'a', 'b' or 'c'
  • GLOB_ONLYDIR - Return only directory items that match the pattern
  • GLOB_ERR - Stops and reads error messages (such as unreadable directories), and ignores all errors by default

Note: GLOB_ERR was added by PHP 5.1.

Similar Functions
Popular Articles