导航首页 » 技术教程 » PHP:basename()的用法_Filesystem函数
PHP:basename()的用法_Filesystem函数 131 2023-12-15   

basename

(PHP 4, PHP 5)

basename — 返回路径中的文件名部分

说明

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

给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名。

参数

path

一个路径。

在 Windows 中,斜线(/)和反斜线()都可以用作目录分隔符。在其它环境下是斜线(/)。

suffix

如果文件名是以 suffix 结束的,那这一部分也会被去掉。

返回值

Returns the base name of the given path. 返回 path 的基本的文件名。

更新日志

版本 说明 4.1.0 增加了参数 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() - 返回文件路径的信息


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103