PHP glob () function

Source: Internet
Author: User
Tags glob
Definition and usage

The glob () function returns a file name or directory that matches the specified mode.

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

Syntax
glob(pattern,flags)
Parameters Description
File Required. Specify the search mode.
Size

Optional. Specify special settings.

  • Glob_mark-Add a diagonal line to each returned item
  • Glob_nosort-returns (unordered) files in the original order in the directory)
  • Glob_nocheck-returns the search mode if no matching file exists.
  • Glob_noescape
  • Glob_brace-extended {a, B, c} to match 'A', 'B' or 'C'
  • Glob_onlydir-returns only directory items that match the pattern.
  • Glob_err-stop and read error messages (such as unreadable Directories). All errors are ignored by default.

Note: glob_err is added in PHP 5.1.

 

 

<? PHP
// Glob ()


// Retrieve all "*. txt" files in the current directory


$ Files = glob ("*. txt ");
Foreach ($ files as $ filename ){
Echo "File Name: $ FILENAME". "file size:". filesize ($ filename). "/N ";
}


// Retrieve all subdirectories starting with "T" in the current directory

$ Files = glob ("T *", glob_onlydir );
Foreach ($ files as $ filename ){
Echo "File Name: $ FILENAME". "file size:". filesize ($ filename). "/N ";
}

// Retrieve all PHP files starting with "D, T, or P" in the current directory

$ Files = glob ("{d, T, P} *. php", glob_brace );
Foreach ($ files as $ filename ){
Echo "File Name: $ FILENAME". "file size:". filesize ($ filename). "/N ";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.