php 使用功能

來源:互聯網
上載者:User
最近自己一直打算學習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潮流網
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.