Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

basename()

Example

Retrieve the filename from a given 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 result of the code above will be:

home.php
home

Definition and Usage

The basename() function extracts the filename from a given path.

Syntax

basename(pathsuffix)

Parameter Values

Parameter

Description

path

Mandatory. Specifies the path to the file.

suffix

Optional. A file extension. If the filename includes this extension, it will be removed from the result.

Technical Details

 

Return Value:

The name of the file in the given path.

PHP Version:

4.0+