PHP dirname() Function
❮ PHP Filesystem ReferenceExample
Return the path of the parent directory:
<?php
echo dirname("c:/testweb/home.php") . "<br />";
echo dirname("c:/testweb/home.php",
2) . "<br />";
echo dirname("/testweb/home.php");
?>
The output of the code above will be:
c:/testweb
c:
/testweb
Definition and Usage
The dirname() function returns the path of the parent directory.
Syntax
dirname(path, levels)
Parameter Values
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 |
Technical Details
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 |
❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.