最近自己一直打算學習php,現在對php 有了一定的瞭解,php文法跟js還是很像的,相信會用js的都可以很快學會php,
接下來給大家介紹個使用 Glob() 尋找檔案
很多PHP的函數都有一個比較長的自解釋的函數名,但是,當你看到?glob()的時候,你可能並不知道這個函數是用來幹什麼的,除非你對它已經很熟悉了。
你可以認為這個函數就好?scandir()一樣,其可以用來尋找檔案。
// 取得所有的尾碼為PHP的檔案 $files = glob('*.php'); print_r($files); /* 輸出: Array ( [0] => phptest.php [1] => pi.php [2] => post_output.php [3] => test.php ) */
你還可以尋找多種尾碼名
// 取PHP檔案和TXT檔案
$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');
// applies the function to each array element
$files = array_map('realpath',$files);
print_r($files);
/* output looks like:
Array ( [0] => C:wampwwwimagesapple.jpg
[1] => C:wampwwwimagesart.jpg )
*/
以上這些是參考網路資訊,最終由IT潮流網整合而來。
詳見:IT潮流網