• PHP Video Tutorials

PHP - Function basename()



The basename() function can return trailing name component of path.

Syntax

string basename ( string path [, string suffix] )

It has given a string containing a path to a file, and this function returns the base name of a file. If the filename ends in the suffix, this can also be cut off.

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

index.php
index
php_function_reference.htm
Advertisements