PHP fgetc() Function
❮ PHP Filesystem ReferenceExample
Read one character from the open file:
<?php
$file = fopen("test.txt","r");
echo fgetc($file);
fclose($file);
?>
Run Example »
Definition and Usage
The fgetc() function returns a single character from an open file.
Note: This function is slow and should not be used on large files. If you need to read one character at a time from a large file, use fgets() to read data one line at a time and then process the line one single character at a time with fgetc().
Syntax
fgetc(file)
Parameter Values
Parameter | Description |
---|---|
file | Required. Specifies the open file to return a single character from |
Technical Details
Return Value: | A single character read from the file on success, FALSE on EOF |
---|---|
PHP Version: | 4.0+ |
Binary Safe: | Yes |
More Examples
Example
Read open file, character by character:
<?php
$file = fopen("test.txt","r");
while (! feof($file)) {
echo fgetc($file);
}
fclose($file);
?>
Run Example »
❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.