Return the path of the parent directory:
<?php
echo dirname("c:/testweb/home.html") . "<br />";
echo dirname("c:/testweb/home.html", 2) . "<br />";
echo dirname("/testweb/home.html");
?>
The output of the code above will be:
c:/testweb
c:
/testweb
The dirname() function returns the path of the parent directory.
dirname(
path,
levels)
Parameter | Description |
---|---|
path | Required. Specifies a path to check |
levels | Optional. An integer that specifies the number of parent directories to go up. Default is 1 |
Return Value: | The path of the parent directory on success |
---|---|
PHP Version: | 4.0+ |
Binary Safe: | Yes, in PHP 5.0 |
PHP Changelog: | PHP 7.0 - Added the levels parameter |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!