From the course: Learning the Standard PHP Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Filtering a directory with GlobIterator

Filtering a directory with GlobIterator - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

Filtering a directory with GlobIterator

- When traversing the file system, you're often interested only in certain types of files. In the previous chapter, we used a conditional statement to find the file name extension, but there's a more direct way to filter files by globbing. If you're not familiar with the expression, globbing means matching file names with wildcard characters or glob patterns. These are the main patterns used by PHP. A question mark matches a single character. An asterisk matches zero or more characters, but not in the same way as in a regular expression. It doesn't mean repeat the previous character zero or more times. It simply means any characters or none at all. A group of characters inside square brackets matches a single character from that group. You can also specify a range of characters inside square brackets by separating them with a hyphen. The example shown here means match a single number in the range from three to seven inclusive. An exclamation mark at the beginning of a group or range…

Contents