- 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
pathinfo() function in PHP
The pathinfo() function returns information about a file path in an array. The pathinfo() function returns an associative array with the following elements −
directory name − returns directory name
basename − returns basename
extension − returns extension
Syntax
pathinfo(path,options)
Parameters
path − The path to be checked.
options − Specify which of the elements to return
- PATHINFO_DIRNAME - return only dirname
- PATHINFO_BASENAME - return only basename
- PATHINFO_EXTENSION - return only extension
Return
The pathinfo() function returns an associative array with the following elements.
directory name − returns directory name
basename − returns basename
extension − returns extension
The following is an example showing all the information since we haven’t set the second parameter.
Example
<?php print_r(pathinfo("/images/architecture.png")); ?>
Output
Array ( [dirname] => /images [basename] => architecture.png [extension] => png )
Let us see how to get only the directory name.
Example
<?php print_r(pathinfo("/images/architecture.png",PATHINFO_DIRNAME)); ?>
Output
/images
Let us see how to get only the basename.
Example
<?php print_r(pathinfo("/images/architecture.png",PATHINFO_BASENAME)); ?>
Output
architecture.png
Let us see how to get only the extension.
Example
<?php print_r(pathinfo("/images/architecture.png",PATHINFO_EXTENSION)); ?>
Output
png
Advertisements