- 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
How to get file name from a path in PHP?
To get the file name from a path, the code is as follows−
Example
<?php $file = pathinfo('/home/cg/root/6985034/main.php'); echo $file['basename'], "
"; ?>
Output
This will produce the following output−
main.php
Example
Let us now see another example −
<?php $path = "/home/cg/root/6985034/main.php"; $file = basename($path, ".php"); echo $file; ?>
Output
This will produce the following output−
main
Advertisements