Directory name; return the directory part of the path; directory name

php dirname() function syntax

Function: Return the directory part of the path.

Syntax: dirname(path)

Parameters:

Parameter Description
path Required. Specifies the path to be checked.

Explanation: The path parameter is a string containing the full path to a file. This function returns the directory name after removing the file name.

php dirname() function example

<?php
$file = "/phpstudy/WWW/index.php";
echo dirname($file);
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

/phpstudy/WWW