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.phpReference: PHP dir() function
參考: PHP dir()函數
翻譯自: https://www.includehelp.com/php/dir-function-with-example.aspx
dir函數
總結
以上是生活随笔為你收集整理的dir函数_PHP dir()函数与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数组重复次数最多的元素递归_在不使用递归
- 下一篇: PHP rewinddir()函数与示例