O'Reilly logo

Programming PHP, 3rd Edition by Peter MacIntyre, Kevin Tatroe, Rasmus Lerdorf

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

glob

Synopsis

globarray(string pattern[, int flags])

Returns a list of filenames matching the shell wildcard pattern given in pattern. The following characters and sequences make matches:

*

Matches any number of any character (equivalent to the regex pattern .*)

?

Matches any one character (equivalent to the regex pattern .)

For example, to process every JPEG file in a particular directory, you might write:

foreach(glob("/tmp/images/*.jpg") as $filename) {
    // do something with $filename
}

The flags value is a bitwise OR of any of the following values:

GLOB_MARK

Adds a slash to each item returned.

GLOB_NOSORT

Returns files in the same order as found in the directory itself. If this is not specified, the names are sorted by ASCII value.

GLOB_NOCHECK

If no files matching pattern are found, pattern is returned.

GLOB_NOESCAPE

Treat backslashes in pattern as backslashes, rather than as the start of an escape sequence.

GLOB_BRACE

In addition to the normal matches, strings in the form {foo, bar, baz} match either “foo”, “bar”, or “baz”.

GLOB_ONLYDIR

Returns only directories matching pattern.

GLOB_ERR

Stop on read errors.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required