php blob 函數快速查詢指定目錄檔案執行個體

來源:互聯網
上載者:User
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

)

*/

搜尋以.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

)

*/

搜尋包括有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

)

*/

在指定目錄搜尋以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

)

*/

返迴文件的絕對路徑,代碼如下:

$files = array_map('realpath',$files);

print_r($files);

Array

(

[0] => D:wwwwww.phpfensi.com-15.php

[1] => D:wwwwww.phpfensi.com-15.php

[2] => D:wwwwww.phpfensi.com-15 .php

)

glob() 函數能做的事比scandir() 函數更強大,可以按照某種模式搜尋檔案.

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.