basename

Returns trailing name component of path

Syntax

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

Parameters

path

A path. On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).

suffix

If the name component ends in suffix this will also be cut off.

Return

Returns the base name of the given path.

Examples

1 · path

<?

$path = "/directory/file.extension";

$return = basename($path);

echo $return;

?>
file.extension

2 · suffix

<?

$path = "/directory/file.extension";
$suffix = ".extension";

$return = basename($path, $suffix);

echo $return;

?>
file

3

<?

echo basename("/directory/file.extension") . PHP_EOL;
echo basename("/directory/file") . PHP_EOL;
echo basename("/directory/..") . PHP_EOL;
echo basename("/directory/.") . PHP_EOL;
echo basename("/directory/") . PHP_EOL;
echo basename("/directory") . PHP_EOL;
echo basename("/..") . PHP_EOL;
echo basename("/.") . PHP_EOL;
echo basename("/") . PHP_EOL;
echo basename("..") . PHP_EOL;
echo basename(".");

?>
file.extension
file
..
.
directory
directory
..
.

..
.

chgrp

chmod

chown

clearstatcache

copy

dirname

disk_free_space

disk_total_space

diskfreespace

fclose

feof

fflush

fgetc

fgetcsv

fgets

file

file_exists

file_get_contents

file_put_contents

fileatime

filectime

filegroup

fileinode

filemtime

fileowner

fileperms

filesize

filetype

flock

fnmatch

fopen

fpassthru

fputcsv

fputs

fread

fscanf

fseek

fstat

ftell

ftruncate

fwrite

glob

is_dir

is_executable

is_file

is_link

is_readable

is_uploaded_file

is_writable

is_writeable

lchgrp

lchown

link

linkinfo

lstat

mkdir

move_uploaded_file

pathinfo

pclose

popen

readfile

readlink

realpath

realpath_cache_get

realpath_cache_size

rename

rewind

rmdir

set_file_buffer

stat

symlink

tempnam

tmpfile

touch

umask

unlink

PHP

Home Menu