Home >Backend Development >PHP Tutorial >Use while loop to read file content character by character_PHP tutorial
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