目录

PHP basename() Function

❮ PHP Filesystem Reference

Example

Return filename from the specified path:

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

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

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

The output of the code above will be:

home.html
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