php使用glob函数快速查询指定目录文件 php使用glob函数快速查询指定目录文件的方法
人气:0想了解php使用glob函数快速查询指定目录文件的方法的相关内容吗,在本文为您仔细讲解php使用glob函数快速查询指定目录文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,glob函数,快速查询,指定目录,文件,下面大家一起来学习吧。
本文实例讲述了php使用glob函数快速查询指定目录文件的方法。分享给大家供大家参考。具体如下:
php搜索当前目录所有文件,代码如下:
复制代码 代码如下:
$array = glob('*.*');
print_r($array );
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 2.asp
[4] => 3.asp
[5] => 4.aspx
[6] => 5.html
[7] => 6.php
[8] => 7.php
[9] => 8.php
[10] => 9.php
)
*/
print_r($array );
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 2.asp
[4] => 3.asp
[5] => 4.aspx
[6] => 5.html
[7] => 6.php
[8] => 7.php
[9] => 8.php
[10] => 9.php
)
*/
搜索以.php结果的php文件,代码如下:
复制代码 代码如下:
$array = glob('*.php');
print_r($array );
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 6.php
[4] => 7.php
[5] => 8.php
[6] => 9.php
)
*/
print_r($array );
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 6.php
[4] => 7.php
[5] => 8.php
[6] => 9.php
)
*/
搜索包括有php,aspx 文件,代码如下:
复制代码 代码如下:
$files = glob('*.{php,aspx}', GLOB_BRACE);
print_r( $files );
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 6.php
[4] => 7.php
[5] => 8.php
[6] => 9.php
[7] => 4.aspx
)
*/
print_r( $files );
/*
Array
(
[0] => 1.php
[1] => 10.php
[2] => 11.php
[3] => 6.php
[4] => 7.php
[5] => 8.php
[6] => 9.php
[7] => 4.aspx
)
*/
在指定目录搜索以1开的php文件
复制代码 代码如下:
$files = glob('../05-15/1*.php');
print_r($files);
/*
Array
(
[0] => ../05-15/1.php
[1] => ../05-15/10.php
[2] => ../05-15/11.php
)
*/
print_r($files);
/*
Array
(
[0] => ../05-15/1.php
[1] => ../05-15/10.php
[2] => ../05-15/11.php
)
*/
返回文件的绝对路径,代码如下:
复制代码 代码如下:
$files = array_map('realpath',$files);
print_r($files);
Array
(
[0] => D:www.qb5200.com-15.php
[1] => D:www.qb5200.com-15.php
[2] => D:www.qb5200.com-15 .php
)
print_r($files);
Array
(
[0] => D:www.qb5200.com-15.php
[1] => D:www.qb5200.com-15.php
[2] => D:www.qb5200.com-15 .php
)
glob()函数能做的事比scandir()函数更强大,可以按照某种模式搜索文件。
希望本文所述对大家的PHP程序设计有所帮助。
加载全部内容