亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 PHP視頻 Detailed explanation of how PHP uses the glob function to traverse files and directories

Detailed explanation of how PHP uses the glob function to traverse files and directories

Dec 21, 2016 pm 04:17 PM
glob

php glob() function returns the file name or directory matching the specified pattern. Therefore, we can use the glob function to find files and traverse directories.

Function description: array glob (string $pattern [, int $flags])

Function: Find the file path that matches the pattern and return an array containing the matching files (directories) (Note: The file being checked must be a server system (cannot be used for remote files)

Parameter description: first parameter: matching pattern; second optional parameter:

GLOB_MARK - add a slash to each returned item

GLOB_NOSORT - follow the file in Original order of occurrences in directory returned (not sorted)

GLOB_NOCHECK - Returns pattern used for search if no files match

GLOB_NOESCAPE - Backslash unescaped metacharacters

GLOB_BRACE - Extended {a,b,c} to match 'a', 'b' or 'c'

GLOB_ONLYDIR - Return only directory entries matching the pattern

Example 1: Get all files and subdirectories under the specified directory

<?php
   $directories = glob("/tmp/*", GLOB_ONLYDIR);//獲取/tmp/目錄下的所有目錄
   $complete = glob("/tmp/*");//獲取/tmp/目錄下的所有目錄和文件
   $files = array_diff($directories, $complete);//獲取/tmp/目錄下的所有文件
 
   echo "Directories in /tmp/<BR>";
   foreach($directories as $val) {
     echo "$val<BR>\n";
   }
   echo "<BR>Files in /tmp/<BR>";
   foreach($files as $val) {
     echo "$val<BR>\n";
   }
?>

Example 2: You Are you still using opendir readdir to traverse files? You are really out!

<?php
$files = glob("dir/*.jpg");
foreach($files as $jpg){
  echo $jpg, "\n";
}
?>

The above is a compilation of information on how to use the glob function in PHP to traverse files and directories. We will continue to add relevant information in the future. Thank you for your support of this site!

For more detailed explanations of how PHP uses the glob function to traverse files and directories, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72