- 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
basename( ) function in PHP
The basename() function gets the the filename component of a path. The file path is set as a parameter.
Syntax
basename(file_path, suffix)
Parameters
file_path − Set the path of file or directory to be checked. Required.
suffix − Set the extension of the file. Optional.
Return
The basename() function returns the basename of the file.
Example
The following is an example that checks for file “new.php” and returns the basename with the extension since we added the suffix parameter.
<?php $file_path = "/backup/myfiles/new.php"; // displays name of the file with extension echo basename($file_path); ?>
Output
new.php
Example
Let us see another example that checks the file and display the basename without the extension.
<?php $file_path = "/backup/myfiles/new.php"; // displays name of the file without extension echo basename($file_path,".php"); ?>
Output
new
Advertisements