Home > php教程 > php手册 > PHP之readdir()函数,phpreaddir函数

PHP之readdir()函数,phpreaddir函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 08:52:12
Original
1376 people have browsed it

PHP之readdir()函数,phpreaddir函数

  最近在学习php文件操作的相关知识,记录一下readdir()函数其中的一个要注意的点

          1、 在$temp=readdir($handle)函数中 readdir获取的是文件名和$handle中的文件夹名,

    一般在程序中遍历文件通过while()循环:

         while($temp=readdir($handel)){}
Copy after login

   但是这种写法的判断语句存在一个问题就是:如果$handle下面有个文件夹的名字为'0',那么$temp=0,while循环就无法进行下去,那么就无法遍历其余的文件,导致程序结果不对,

正确的写法:

    while(($temp=readdir($handel))!==false){}//用不全等于是区分如果文件夹名字为0的时候,那么0!==false,仍然可以遍历
Copy after login

      

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template