当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > glob() 函数

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 glob() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 518 ::
收藏到网摘: n/a

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描述
pattern Required. Specifies the pattern to search for
必要参数。指定搜索的样式
flags Optional. 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

<?php
print_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

<?php
print_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.htm
[6] => test.ini
[7] => test.php
[8] => test.txt
[9] => test2.txt
)

评论 (0) All

登陆 | 还没注册?