Current Location: Home> Function Categories> basename

basename

Returns the file name part in the path
Name:basename
Category:File system
Programming Language:php
One-line Description:Returns the file name part in the path.

Definition and usage

basename() function returns the file name part in the path.

Example

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

//Show filename with file extension
echo basename ( $path ) ;

//Show file names without file extension
echo basename ( $path , ".php" ) ;
?>

Output:

 home.php
home

grammar

 basename ( path , suffix )
parameter describe
path Required. Specify the path to be checked.
suffix Optional. Specify file extensions. If the file has suffix, this extension will not be output.
Similar Functions
  • Delete directory rmdir

    rmdir

    Deletedirectory
  • See unlink() or unset() (PHP does not have delete keywords or functions) delete

    delete

    Seeunlink()orunset()
  • Test whether the file pointer reaches the end of the file feof

    feof

    Testwhetherthefilepo
  • Create a temporary file tmpfile

    tmpfile

    Createatemporaryfile
  • Determine whether the given file name is executable is_executable

    is_executable

    Determinewhethertheg
  • Get the inode of the file fileinode

    fileinode

    Gettheinodeofthefile
  • Truncate the file to a given length ftruncate

    ftruncate

    Truncatethefiletoagi
  • Positioning in file pointer fseek

    fseek

    Positioninginfilepoi