PHP fgetc() Function
Definition and Usage
The fgetc() function reads a character from the file pointer.
Syntax
fgetc(file)
Parameter | Description |
---|---|
file | Required. Specifies the file to be checked. |
Description
Returns a string containing a single character, which is from file reaching EOF, it returns false.
The file pointer must be valid and must point to a file obtained by fopen() or fsockopen() successfully opened (but not yet been fclose() Closing) the file.
Tips and Comments
Attention:This function may return a boolean value false, but it may also return a non-boolean value equivalent to false, such as 0 or "".
Note:This function can be safely used for binary objects.
Instance
Example 1
<?php $file = fopen("test.txt","r"); echo fgetc($file); fclose($file); ?>
Output similar to:
H
Example 2
<?php $file = fopen("test.txt","r"); while (! feof ($file)) { echo fgetc($file); } fclose($file); ?>
Output similar to:
Hello, this is a test file.