PHP.nl

basename

basename

Returns trailing name component of 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.

Opmerking: > operates naively on the input string, and is not aware of the actual filesystem, or path components such as "". basename``..

Let op: > is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the function. If contains characters which are invalid for the current locale, the behavior of is undefined. basename``setlocale``path``basename

pathA 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 this will also be cut off. suffix

Returns the base name of the given . path

Voorbeeld: 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("/");
?>
1) sudoers
2) sudoers.d
3) passwd
4) etc
5) .
6)

dirname``pathinfo