php7列目录_返回路径中的目录部分 - PHP 7 中文文档

(PHP 4, PHP 5, PHP 7)

dirname – 返回路径中的目录部分

说明

dirname

( string $path

) : string

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

参数

path

一个路径。

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

返回值

返回 path 的父目录。

如果在 path

中没有斜线,则返回一个点('.'),表示当前目录。否则返回的是把

path 中结尾的

/component(最后一个斜线以及后面部分)去掉之后的字符串。

更新日志

版本

说明

5.0.0

dirname() 的操作从 PHP 5.0.0 版开始是二进制安全的。

4.0.3

在这个版本中,dirname() 被修正为

POSIX 兼容。

范例

Example #1 dirname() 例子

echo "1) " . dirname("/etc/passwd") . PHP_EOL; // 1) /etc

echo "2) " . dirname("/etc/") . PHP_EOL; // 2) / (or on Windows)

echo "3) " . dirname("."); // 3) .

?>

注释

Note:

dirname() operates naively on the input string,

and is not aware of the actual filesystem, or path components such

as "..".

Note:

dirname() is locale aware, so for it to see the

correct directory name with multibyte character paths, the matching locale must

be set using the [setlocale()](php7/function.setlocale) function.

Note:

Since PHP 4.3.0, you will often get a slash or a dot back from

dirname() in situations where the older

functionality would have given you the empty string.

检查下面发生变化的例子:

// PHP 4.3.0 以前

dirname('c:/'); // 返回 '.'

// PHP 4.3.0 以后

dirname('c:/x'); // 返回 'c:'

dirname('c:/Temp/x'); // 返回 'c:/Temp'

dirname('/x'); // 返回 ''

?>

参见

[basename()](php7/function.basename) – 返回路径中的文件名部分

[pathinfo()](php7/function.pathinfo) – 返回文件路径的信息

[realpath()](php7/function.realpath) – 返回规范化的绝对路径名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值