
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
dirname()function in PHP
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
<?php $file_path = "D:/amit/java.docx"; $dir_name = dirname($file_path); echo "Name of the directory: $dir_name
"; ?>
Output
Name of the directory: D:/amit
Let us see another example.
Example
<?php $file_path = "/amit/java.docx"; $dir_name = dirname($file_path); echo "Name of the directory: $dir_name
"; ?>
Output
Name of the directory: /amit
- Related Articles
- How to work with the dirname attribute in HTML?
- strcmp() function in PHP
- strcoll() function in PHP
- strcspn() function in PHP
- strip_tags() function in PHP
- stripcslashes() function in PHP
- stripos() function in PHP()
- stristr() function in PHP
- stripslashes() function in PHP
- strlen() function in PHP
- strnatcasecmp() function in PHP
- strnatcmp() function in PHP
- strncasecmp() function in PHP
- strncmp() function in PHP
- strpbrk() function in PHP

Advertisements