PHP函数glob()

glob() 函数依照 libc glob() 函数使用的规则寻找所有与 pattern 匹配的文件路径.

$files=glob(‘*.php’);  

print_r($files);  

/*

Array  

(  

    [0]=>phptest.php  

    [1]=>pi.php  

    [2]=>post_output.php  

    [3]=>test.php  

)  

*/ 



$files=glob(‘*.{php,txt}’,GLOB_BRACE);  

print_r($files);  

/*

Array  

(  

    [0]=>phptest.php  

    [1]=>pi.php  

    [2]=>post_output.php  

    [3]=>test.php  

    [4]=>log.txt  

    [5]=>test.txt  

)  

*/ 



//请注意,这些文件其实是可以返回一个路径,这取决于查询条件

$files=glob(‘../images/a*.jpg’);  

print_r($files);  

/*

Array  

(  

    [0]=>../images/apple.jpg  

    [1]=>../images/art.jpg  

)  

*/ 

 

//如果你想获得每个文件的完整路径,你可以调用realpath()函数

$files=glob(‘../images/a*.jpg’);  

$files=array_map(‘realpath’,$files);  

print_r($files);  

/*

Array  

(  

    [0]=>C:\wamp\www\images\apple.jpg  

    [1]=>C:\wamp\www\images\art.jpg  

)  

*/ 

你可能感兴趣的:(PHP)