PHP glob() Function

Definition

The glob() function returns an array of filenames or directories matching a specified pattern.

Syntax

PHP glob() Function has the following syntax.

glob(pattern,flags)

Parameter

ParameterIs RequiredDescription
patternRequired.Pattern to search for
flagsOptional.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 - Stop on errors. Errors are ignored by default

Return

This function returns an array of files/directories, or FALSE on failure.

Example

Returns an array of filenames or directories matching a specified pattern


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

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions