dir函数_PHP dir()函数与示例

dir函数

PHP dir()函数 (PHP dir() function)

dir() function is an instance of the directory class, it is used to read the directory, it includes handle and path properties – which can be used to get the resource id and path to the directory. Both handle and path have read(), rewind(), and close() methods.

dir()函数是目录类的实例,用于读取目录,它包括句柄和路径属性–可用于获取资源ID和目录的路径。 句柄和路径都具有read() , rewind()和close()方法。

Syntax:

句法:

    dir(directory,context);

Parameter(s):

参数:

  • directory – It is used to specify the path to the directory to be opened.

    directory –用于指定要打开的目录的路径。

  • context – It is an optional parameter; it defines the context (a set of options that can modify the behavior of the stream).

    上下文 –它是一个可选参数; 它定义了上下文(一组可以修改流行为的选项)。

Return value:

返回值:

On success – it returns an instance to the directory, on fail – it returns "FALSE".

成功–将实例返回目录;失败–将返回“ FALSE”。

Example: PHP code to demonstrate example of dir() function

示例:PHP代码演示dir()函数的示例

<?php 
//path to current working directory
$cwd = dir(getcwd());

echo "Directory handle: " . $cwd->handle . "<br>";
echo "Current path: " . $cwd->path . "<br>";

//reading & printing the filenames using dir()
while (($file = $cwd->read()) !== false){ 
  echo "File: " . $file . "<br>"; 
} 

//closing the dir instance
$cwd->close(); 
?>

Output

输出量

Directory handle: Resource id #5
Current path: /home
File: .
File: ..
File: main.php

Reference: PHP dir() function

参考: PHP dir()函数

翻译自: https://www.includehelp.com/php/dir-function-with-example.aspx

dir函数

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值