Discussion board
How to read a File Character by Character?
By prabeen patra
How to read a File Character by Character?????
Reply
Post   Reset
Teacher SiliconIndia replied to prabeen patra Wednesday, March 17, 2010
Hi Prabeen,
The fgetc() function is used to read a single character from a file.
Note: After a call to this function the file pointer moves to the next character.
Example
The example below reads a file character by character, until the end of file is reached:
<?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
while (!feof($file))
{
echo fgetc($file);
}
fclose($file);
?>