php glob() 函数

Definition and Usage
定义和用法

The glob() function returns an array of filenames or directories matching a specified pattern.
glob()函数的作用是:以数组的形式返回与指定模式相匹配的文件名或目录。

This function returns an array of files/directories, or FALSE on failure.
如果函数执行成功,将以数组的形式返回文件名或目录;如果执行失败,将返回False。

Syntax
语法

glob(pattern,flags)

 

Parameter参数Description描述
patternRequired. Specifies the pattern to search for
必要参数。指定搜索的样式
flagsOptional. Specifies special settings.
可选参数。指定详细的属性设置。

Possible values:
可用值:

  • GLOB_MARK - Adds a slash to each item returned
    GLOB_MARK – 给每一个返回的项填加一条斜杠(“/”)[slash]
  • GLOB_NOSORT - Return files as they appear in the directory (unsorted)
    GLOB_NOSORT – 返回目录中的文件[不进行排序]
  • GLOB_NOCHECK - Returns the search pattern if no match were found
    GLOB_NOCHECK – 如果没有与指定的模式向匹配的项,那么就返回这个样式
  • GLOB_NOESCAPE - Backslashes do not quote metacharacters
    GLOB_NOESCAPE – 使用反斜杠(“/”),不将元字符[metacharacter]放入引号内进行引证。
  • GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'
    GLOB_BRACE – 使{a,b,c}与'a', 'b', 或 'c'相匹配
  • GLOB_ONLYDIR - Return only directories which match the pattern
    GLOB_ONLYDIR – 只返回与指定样式相匹配的样式
  • GLOB_ERR - (added in PHP 5.1) Stop on errors (errors are ignored by default)
    GLOB_ERR – 出现错误时停止(仅在PHP5.1以上版本支持。如果不设置这个参数,那么错误将被忽略)

 


Example 1
案例1

<?phpprint_r(glob("*.txt"));?> 

The output of the code above could be:
上述代码将输出下面的结果:

Array([0] => target.txt[1] => source.txt[2] => test.txt[3] => test2.txt)

 


Example 2
案例2

<?phpprint_r(glob("*.*"));?> 

The output of the code above could be:
上述代码将输出下面的结果:

Array([0] => contacts.csv[1] => default.php[2] => target.txt[3] => source.txt[4] => tem1.tmp[5] => test.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值