PHP pathinfo() 函數(shù)
定義和用法
pathinfo() 函數(shù)以數(shù)組的形式返回文件路徑的信息。
語(yǔ)法
pathinfo(path,options)
參數(shù) | 描述 |
---|---|
path | 必需。規(guī)定要檢查的路徑。 |
process_sections |
可選。規(guī)定要返回的數(shù)組元素。默認(rèn)是 all。 可能的值:
|
說(shuō)明
pathinfo() 返回一個(gè)關(guān)聯(lián)數(shù)組包含有 path 的信息。
包括以下的數(shù)組元素:
- [dirname]
- [basename]
- [extension]
提示和注釋
注釋:如果不是要求取得所有單元,則 pathinfo() 函數(shù)返回字符串。
例子
例子 1
<?php print_r(pathinfo("/testweb/test.txt")); ?>
輸出:
Array ( [dirname] => /testweb [basename] => test.txt [extension] => txt )
例子 2
<?php print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME)); ?>
輸出:
test.txt