PHP fgetc() Function
In this chapter you will learn:
- Definition for PHP fgetc() Function
- Syntax for PHP fgetc() Function
- Parameter for PHP fgetc() Function
- Return for PHP fgetc() Function
- Example - Read one a character from a file
- Example - Read file character by character
Definition
The fgetc() function returns a single character from an open file.
Syntax
PHP fgetc() Function has the following syntax.
fgetc(file)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to check |
Return
PHP fgetc() Function returns a single character from an open file.
Example 1
<?php//from j av a 2 s .c o m
$file = fopen("data.txt","r");
echo fgetc($file);
fclose($file);
?>
Example 2
Read file character by character:
<?php//j a v a 2 s.c om
$file = fopen("data.txt","r");
while (! feof ($file)){
echo fgetc($file);
}
fclose($file);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP fgets() Function
- Syntax for PHP fgets() Function
- Parameter for PHP fgets() Function
- Return for PHP fgets() Function
- Example - reads a large log line by line
Home » PHP Tutorial » PHP File Functions