php uses the glob function to quickly query files in a specified directory,
The example in this article describes how PHP uses the glob function to quickly query files in a specified directory. Share it with everyone for your reference. The details are as follows:
php searches all files in the current directory, the code is as follows:
Copy code The code is as follows:
$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
)
*/
Search for php files with .php results, the code is as follows:
Copy code The code is as follows:
$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
)
*/
Search includes php, aspx files, the code is as follows:
Copy code The code is as follows:
$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
)
*/
Search for php files opening with 1 in the specified directory
Copy code The code is as follows:
$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
)
*/
Return the absolute path of the file, the code is as follows:
Copy code The code is as follows:
$files = array_map('realpath',$files);
print_r($files);
Array
(
[0] => D:www.jb51.net-15.php
[1] => D:www.jb51.net-15.php
[2] => D:www.jb51.net-15 .php
)
The glob() function can do something more powerful than the scandir() function, and can search files according to a certain pattern.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/912284.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912284.htmlTechArticlephp uses the glob function to quickly query the specified directory file. This article describes the example of php using the glob function to quickly query the specified directory. file method. Share it with everyone for your reference. Specifically...