Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

dirname()

Example

Retrieve 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 result of the code above will be:

c:/testweb
c:
/testweb

Definition and Usage

The dirname() function returns the path to the parent directory.

Syntax

dirname(pathlevels)

Parameter Values

 

Parameter

Description

path

Mandatory. Specifies the path to be checked.

levels

Optional. An integer indicating the number of parent directories to traverse. The default is 1.

Technical Details

Return Value:

The parent directory path upon success.

PHP Version:

4.0+

Binary Safe:

Yes, in PHP 5.0

PHP Changelog:

PHP 7.0 introduced the levels parameter.