PHP uses the Glob function to quickly query the method of specifying a directory file, _php tutorial

Source: Internet
Author: User
Tags glob

PHP uses the Glob function to quickly query the method of the specified directory file,


This example describes how PHP uses the Glob function to quickly query a specified directory file. Share to everyone for your reference. Specific as follows:

PHP searches the current directory for all files, the code is as follows:
Copy CodeThe 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
[Ten] = 9.php
)
*/
To search for PHP files with the. PHP results, the code is as follows:
Copy CodeThe 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
)
*/
The search includes a php,aspx file with the following code:
Copy CodeThe 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 with 1 in the specified directory
Copy CodeThe 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 to the file with the following code:
Copy CodeThe 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
)
What the Glob () function can do is more powerful than the Scandir () function and can search for files in a certain pattern.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/912284.html www.bkjia.com true http://www.bkjia.com/PHPjc/912284.html techarticle PHP uses the Glob function to quickly query the method of specifying a directory file, and this example describes how PHP uses the Glob function to quickly query the specified directory file. Share to everyone for your reference. Specific ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.