Tuesday, 27 August 2013

PHP Function basename()

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

No comments:

Post a Comment