PHP fgetc() Function
Definition and Usage
The fgetc() function reads a character from the file pointer.
Syntax
fgetc(file)
Parameters | Description |
---|---|
file | Required. Specifies the file to be checked. |
Description
returns a string containing a single character, which is from file reached. If EOF is encountered, false is returned.
The file pointer must be valid and must point to a file obtained by fopen() or fsockopen() successfully opened (but not yet been fclose() of a file closed) but has not yet been
Tips and Comments
Note:This function may return a boolean value false, but it may also return a non-boolean value that is 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.