No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

basename

(PHP 4, PHP 5, PHP 7)

basenameReturns trailing name component of path

Description

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

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 "..".

Caution

basename() is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the setlocale() function.

PHP: basename - Manual Home of Manuel PHP  Contents Haut

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.

PHP: basename - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns the base name of the given path.

PHP: basename - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 basename() example

<?php
echo "1) ".basename("/etc/sudoers.d"".d").PHP_EOL;
echo 
"2) ".basename("/etc/sudoers.d").PHP_EOL;
echo 
"3) ".basename("/etc/passwd").PHP_EOL;
echo 
"4) ".basename("/etc/").PHP_EOL;
echo 
"5) ".basename(".").PHP_EOL;
echo 
"6) ".basename("/");
?>

The above example will output:

1) sudoers
2) sudoers.d
3) passwd
4) etc
5) .
6) 

PHP: basename - Manual Home of Manuel PHP  Contents Haut

See Also

  • dirname() - Returns a parent directory's path
  • pathinfo() - Returns information about a file path

Find a PHP function
Error Infobrol

Can not display this page of the Infobrol website

Type of error (18-01)

Unknown format specifier "&"

Please try again in a few minutes…

Return to the home page




Steph