- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements