The fgetc() function returns a single character from an open file.
fgetc(file)
parameter | describe |
---|---|
file | Required. Specifies the documents to be checked. |
Note: This function is very slow with large files, so it is not intended for use with large files. If you need to read one character at a time from a large file, use fgets() to read the data one line at a time, and then use fgetc() to process the data one line at a time.
<?php$file = fopen("test2.txt","r");echo fgetc($file);fclose($file);?>
The above code will output:
H
Read a file character by character:
<?php$file = fopen("test2.txt","r");while (! feof ($file)) { echo fgetc($file); }fclose($file);?>
The above code will output:
Hello, this is a test file.