PHP dirname() function

This is used to get the parent directory name of the given directory or path to a file. It returns the directory name one above the current given directory.

Syntax

dirname($path, $level);

$path is the required parameter, it is the path to a file and $level is an optional parameter. It is an integer value greater than 0. It defines the number of levels up to the given path.

Example

<?php
    echo dirname('d:/media/animation.php');
	echo dirname('/demo/php/test', 2);
?>

Output of the above code

d:/media
/demo




Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language