pathinfo()
可輕鬆取檔案名稱、副檔名、根目錄相對路徑、資料夾名
用法一
pathinfo($path, PATHINFO_EXTENSION); // 參數 (選用) PATHINFO_DIRNAME //完整路徑 PATHINFO_BASENAME //完整檔名 PATHINFO_EXTENSION //副檔名 PATHINFO_FILENAME //檔名
用法二
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php'); echo $path_parts['dirname'], "n"; echo $path_parts['basename'], "n"; echo $path_parts['extension'], "n"; echo $path_parts['filename'], "n"; // since PHP 5.2.0
output:
/www/htdocs/inc lib.inc.php php lib.inc
參考:
http://stackoverflow.com/questions/10368217/how-to-get-the-file-extension-in-php
http://php.net/manual/en/function.pathinfo.php
http://php.net/manual/en/function.pathinfo.php