當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP SplFileInfo::getPathInfo()用法及代碼示例


SplFileInfo::getPathInfo()函數是PHP中的標準PHP庫(SPL)的內置函數,用於獲取路徑的SplFileInfo對象。

用法:

SplFileInfo::getPathInfo( $class )

參數:該函數接受可選的單個參數$class。它用於指定SplFileInfo派生類名稱的名稱。


返回值:此函數返回文件的父路徑的SplFileInfo對象。

以下示例程序旨在說明SplFileInfo::getPathInfo()函數。

程序1:

<?php 
  
// PHP Program to illustrate  
// Splfileinfo getMTime function 
   
$file = new SplFileInfo('/var/www/html/gfg.php'); 
   
$info = $file->getPathInfo(); 
print_r($info); 
   
?>
輸出:
SplFileInfo Object
(
    [pathName:SplFileInfo:private] => /var/www/html
    [fileName:SplFileInfo:private] => html
)

程序2:

<?php 
  
// Use array to check multiple 
// files path 
    
$GFG = array ( 
    "/home/rajvir/Desktop/GeeksforGeeks/dummy.php", 
    "/home/rajvir/Desktop/gfg.txt", 
    "/var/www/html/gfg.php", 
    "dummy.php"
); 
    
foreach ($GFG as &$file_name) { 
  
    // Create new SplFile Object 
    $file = new SplFileInfo($file_name); 
   
    // Print result 
    $info = $file->getPathInfo(); 
    print_r($info); 
    echo "</br>"; 
} 
?>
輸出:
SplFileInfo Object
(
    [pathName:SplFileInfo:private] => /home/rajvir/Desktop/GeeksforGeeks
    [fileName:SplFileInfo:private] => GeeksforGeeks
)
SplFileInfo Object
(
    [pathName:SplFileInfo:private] => /home/rajvir/Desktop
    [fileName:SplFileInfo:private] => Desktop
)
SplFileInfo Object
(
    [pathName:SplFileInfo:private] => /var/www/html
    [fileName:SplFileInfo:private] => html
)
SplFileInfo Object
(
    [pathName:SplFileInfo:private] => .
    [fileName:SplFileInfo:private] => .
)

參考: http://php.net/manual/en/splfileinfo.getpathinfo.php



相關用法


注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplFileInfo::getPathInfo() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。