0

Syntax

string basename ( string $path [, string $suffix] );

Definition and Usage

Given a string containing a path to a file, this function will return the base name of the file.

Paramters

ParameterDescription
pathA file path.
suffixIf the filename ends in suffix this will also be cut off.

Return Value

Returns the base name of the given path.

Example

Following is the usage of this function:
<?php
$path = "/home/httpd/html/index.php";
$file = basename($path);         
echo "File name is $file\n";
$file = basename($path, ".php");
echo "File name is $file\n";
?>
This will produce following result:
File name is index.php
File name is index

Post a Comment

 
Top