如何在php中获取父文件夹的父文件夹的名称?
示例:/var/www/test/test2/index.php
在index.php中如何获取/ test /文件夹的名称?
答案 0 :(得分:3)
您可以使用dirname()
:
$path = "/var/www/test/test2/index.php";
// PHP 7.0 and up:
$parent_of_parent = dirname($path, 2);
// earlier versions:
$parent_of_parent = dirname(dirname($path));