PHP fgetc() Function
Definition
The fgetc() function returns a single character from an open file.
Syntax
PHP fgetc() Function has the following syntax.
fgetc(file)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to check |
Return
PHP fgetc() Function returns a single character from an open file.
Example 1
<?php//from w ww . ja v a 2 s . co m
$file = fopen("data.txt","r");
echo fgetc($file);
fclose($file);
?>
Example 2
Read file character by character:
<?php/* w w w .j a va 2s. c o m*/
$file = fopen("data.txt","r");
while (! feof ($file)){
echo fgetc($file);
}
fclose($file);
?>