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
相關用法
- d3.js d3.lab()用法及代碼示例
- PHP exp()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP abs()用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP tan( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- d3.js d3.sum()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplFileInfo::getPathInfo() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。