PHP basename() Function

PHP basename Function


Definition:

The basename() function in PHP is an inbuilt function which is used to return the base name of a file if the path of the file is provided as a parameter to the basename() function.

Syntax

   basename(pathsuffix)

Parameter 
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

Errors And Exception:

  1. The basename() function doesn’t recognise path components such as ‘..’ .
  2. The basename() function operates on the input string provided by the user and is unaware of the actual filesystem.
  3. Both slashes, forward slash (/) and backslash () are used as directory separator character on a windows platform whereas it is just a forward slash (/) in other environments.

Given below example Return filename from the specified path:

Output :  index.php
                index