English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP basename() Function Usage and Example

PHP Filesystem Reference Manual

The basename() function can return the file name part in the path.

Syntax

string basename ( string path [, string suffix] )

It returns a string containing the file path and this function returns the base name of the file. If the file name ends with a suffix, it can also be truncated.

Online Example

<?php
   $path = ""/PhpProject/index.php";
   $file = basename($path);  //  $file is set to "index.php"
   echo $file . "\n";
   
   $file = basename($path, ".php");  // $file is set to "index"
   echo $file;
?>

Output Result

index.php
index

PHP Filesystem Reference Manual