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函数
还没有评论,来说两句吧...