Home Top Ad

PHP basename() Function

Share:

 

php basename

Example

Return filename from the specified path:

<?php
$path = "/testweb/home.php";

//Show filename
echo basename($path) ."<br/>";

//Show filename, but cut off file extension for ".php" files
echo basename($path,".php");
?>

The output of the code above will be:

home.php
home


Definition and Usage

The basename() function returns the filename from a path.

Syntax

basename(pathsuffix)

Parameter Values

ParameterDescription
pathRequired. Specifies a file path
suffixOptional. A file extension. If the filename has this file extension, the file extension will be cut off


Technical Details

Return Value:The filename of the specified path
PHP Version:4.0+


Aucun commentaire