PHP dirname() 函式
❮ PHP 檔案系統參考示例
返回父目錄的路徑
<?php
echo dirname("c:/testweb/home.php") . "<br />";
echo dirname("c:/testweb/home.php", 2) . "<br />";
echo dirname("/testweb/home.php");
?>
上面程式碼的輸出將是
c:/testweb
c
/testweb
定義和用法
dirname() 函式返回父目錄的路徑。
語法
dirname(path, levels)
引數值
引數 | 描述 |
---|---|
path | 必需。指定一個要檢查的路徑 |
levels | 可選。一個整數,指定要向上追溯的父目錄的數量。預設為 1 |
技術詳情
返回值 | 成功時返回父目錄的路徑 |
---|---|
PHP 版本 | 4.0+ |
二進位制安全 | 是,在 PHP 5.0 中 |
PHP 更新日誌 | PHP 7.0 - 添加了 levels 引數 |
❮ PHP 檔案系統參考