PHP dirname() Function

Definition and Usage

The dirname() function returns the directory part of the path.

Syntax

dirname(path)
Parameter Description
path Required. Specifies the path to be checked.

Description

path The parameter is a string that contains a full path to a file. The function returns the directory name without the file name.

Example

<?php
echo dirname("c:/testweb/home.php");
echo dirname("/testweb/home.php");
?>

Output:

c:/testweb
/testweb