Home >Backend Development >PHP Tutorial >Use while loop to read file content character by character_PHP tutorial

Use while loop to read file content character by character_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:53:391194browse

01
02

03
//Use the while loop to read the file content character by character
04
//feof() is used to detect whether the file pointer reaches the end of the file
05

06
$filePath = '/Users/Cuffica/Desktop/addicted.rtf';
07
$fp = fopen($filePath,'r');
08
while(!feof($fp)){                                                                                                                                                                                                                                                    // When the condition is 1 and always true, execute the command repeatedly and enter an infinite loop
09
echo fgetc($fp); //Note that the accepted parameters are handles, not file names
10
}
11

12
fclose($fp); //Remember to close the file after use
13

14
?>
Author: dark circles

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478010.htmlTechArticle01 ?php 02 03 //Use the while loop to read the file content character by character 04 //feof() is used To detect whether the file pointer reaches the end of the file 05 06 $filePath = /Users/Cuffica/Desktop/addicte...
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