dirname()function in PHP

PHPProgrammingServer Side Programming

The dirname() function returns the directory name from the specified path. If the path has no slashes, a dot ('.') is returned. This indicates the current directory.

Syntax

dirname(file_path)

Parameters

  • file_path − File to be specified.

Return

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

Example

 Live Demo

<?php
   $file_path = "D:/amit/java.docx";
   $dir_name = dirname($file_path);
   echo "Name of the directory: $dir_name\n";
?>

Output

Name of the directory: D:/amit

Let us see another example.

Example

 Live Demo

<?php
   $file_path = "/amit/java.docx";
   $dir_name = dirname($file_path);
   echo "Name of the directory: $dir_name\n";
?>

Output

Name of the directory: /amit
raja
Published on 03-Oct-2018 12:10:09
Advertisements