Read one character from the open file:
<?php
$file = fopen("test.txt","r");
echo fgetc($file);
fclose($file);
?>
Run Example »
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().
fgetc(
file)
Parameter | Description |
---|---|
file | Required. Specifies the open file to return a single character from |
Return Value: | A single character read from the file on success, FALSE on EOF |
---|---|
PHP Version: | 4.0+ |
Binary Safe: | Yes |
Read open file, character by character:
<?php
$file = fopen("test.txt","r");
while (! feof($file)) {
echo fgetc($file);
}
fclose($file);
?>
Run Example »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!