PHP dirname() Function

PHP dirname Function


Definition :

The PHP dirname() function returns a string containing the path of a file or directory, this function will return the parent directory's path that is levels up from the current directory.

Syntax

   dirname(pathlevels)

Parameter 
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

Example: dirname() example

The example below shows the usage of dirname() function.

Output : 

/usr/example/fig
/usr/example
/usr
.
/usr/example