PHP basename() Function

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

string basename ( string $path [, string $suffix ] )

Given a string containing the path to a file or directory, this function will return the trailing name component.

Note -

basename() operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".

Example -

The above example will output:

Example -

ParameterDescription
pathRequired. Specifies the path to check
suffixOptional. Specifies a file extension. If the filename has this file extension, the file extension will not show