PHP glob() 函數(shù)
定義和用法
glob() 函數(shù)返回匹配指定模式的文件名或目錄。
該函數(shù)返回一個包含有匹配文件 / 目錄的數(shù)組。如果出錯返回 false。
語法
glob(pattern,flags)
參數(shù) | 描述 |
---|---|
file | 必需。規(guī)定檢索模式。 |
size |
可選。規(guī)定特殊的設(shè)定。
注釋:GLOB_ERR 是 PHP 5.1 添加的。 |
例子
例子 1
<?php print_r(glob("*.txt")); ?>
輸出類似:
Array ( [0] => target.txt [1] => source.txt [2] => test.txt [3] => test2.txt )
例子 2
<?php print_r(glob("*.*")); ?>
輸出類似:
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 )