Read a single character from the open file.
<?php $file = fopen(“test.txt”,“r”); echo fgetc($file); fclose($file); ?> |
The fgetc() function returns a single character from an open file.
Note: This function can be slow for large files. For large files, consider using fgets() to read data line by line and then process each line one character at a time with fgetc().
fgetc(file) |
Parameter |
Description |
file |
Mandatory. Specifies the open file from which to return a single character. |
Return Value: |
Returns a single character read from the file on success, or |
PHP Version: |
4.0+ |
Binary Safe: |
Yes |
Read the open file one character at a time.
<?php $file = fopen(“test.txt”,“r”); while (! feof($file)) { echo fgetc($file); } fclose($file); ?> |