PHP dir() 函数
PHP 教程
· 2019-01-24 12:43:25
实例
使用 dir() 函数:
<?php
$d = dir(getcwd());
echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";
while (($file = $d->read()) !== false){
echo "filename: " . $file . "<br>";
}
$d->close();
?>
$d = dir(getcwd());
echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";
while (($file = $d->read()) !== false){
echo "filename: " . $file . "<br>";
}
$d->close();
?>
结果:
Handle: Resource id #2
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: default.html
filename: demo_array.html
filename: demo_array.htm
...
...
...
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: default.html
filename: demo_array.html
filename: demo_array.htm
...
...
...
定义和用法
dir() 函数返回 Directory 类的实例。该函数用于读取一个目录,包含如下:
- 给定的要打开的目录
- dir() 的 handle 和 path 两个属性是可用的
- handle 和 path 属性有三个方法:read()、rewind() 和 close()
语法
dir(directory,context);
| 参数 | 描述 |
|---|---|
| directory | 必需。规定要打开的目录。 |
| context | 可选。 |
技术细节
| 返回值: | 返回 Directory 类的实例。失败则返回 FALSE。 |
|---|---|
| PHP 版本: | 4.0+ |
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Spring Into HTML and CSS
Molly E. Holzschlag / Addison-Wesley Professional / 2005-5-2 / USD 34.99
The fastest route to true HTML/CSS mastery! Need to build a web site? Or update one? Or just create some effective new web content? Maybe you just need to update your skills, do the job better. Welco......一起来看看 《Spring Into HTML and CSS》 这本书的介绍吧!