(PHP 4, PHP 5)
basename — 返回路徑中的文件名部分
說明
string basename ( string$path
[, string $suffix
] )
給出一個包含有指向一個文件的全路徑的字符串,本函數(shù)返回基本的文件名。
參數(shù)
path
一個路徑。
在 Windows 中,斜線(/)和反斜線()都可以用作目錄分隔符。在其它環(huán)境下是斜線(/)。
suffix
如果文件名是以
suffix
結束的,那這一部分也會被去掉。
返回值
Returns the base name of the given path
.
返回 path
的基本的文件名。
更新日志
版本
說明
4.1.0
增加了參數(shù) suffix
范例
Example #1 basename() 例子
<?php
echo "1) ".basename("/etc/sudoers.d", ".d").PHP_EOL;
echo "2) ".basename("/etc/passwd").PHP_EOL;
echo "3) ".basename("/etc/").PHP_EOL;
echo "4) ".basename(".").PHP_EOL;
echo "5) ".basename("/");
?>
以上例程會輸出:
1) sudoers 2) passwd 3) etc 4) . 5)
注釋
Note:
basename() operates naively on the input string, and is not aware of the actual filesystem, or path components such as "..".
Note:
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.
參見
dirname() - 返回路徑中的目錄部分 pathinfo() - 返回文件路徑的信息