PHP offers many functions for file manipulation. The fgetc
function in PHP reads a single character from an already open file.
<?php$file = fopen("test.txt","r"); // open the fileecho fgetc($file);echo " ";while(!feof($file)) //checks if at end of the file{echo fgetc($file); //reads one character from the file}fclose($file); // close the file?>
The file test.txt
is opened and associated with the file pointer $file
.
A single call to the function returns a single character.
Subsequent calls to the function resume from the position of the last read character and, using this function in a loop, the entire file contents can be read character by character.
Free Resources