Home >php教程 >php手册 >利用while循环逐字符读取文件内容

利用while循环逐字符读取文件内容

WBOY
WBOYOriginal
2016-06-13 10:52:021289browse

01
02
 
03
//利用while循环,逐字符读取文件内容
04
//feof()用于检测文件指针是否到了文件结束的位置
05
 
06
$filePath = '/Users/Cuffica/Desktop/addicted.rtf';
07
$fp = fopen($filePath,'r');
08
while(!feof($fp)){                              //当条件为1,始终为true时,反复执行命令,进入死循环
09
    echo fgetc($fp);        //注意,接受参数为句柄,不是文件名
10
}
11
 
12
fclose($fp);                //使用后记得关闭文件
13
 
14
?>
作者:黑眼圈

Statement:
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