PHP basename() Function

❮ PHP Filesystem Reference

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(path, suffix)

Parameter Values

Parameter Description
path Required. Specifies a file path
suffix Optional. 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+

❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.