php8.5
Home/ Manual/ filesystem / functions/ fgetc

fgetc

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Gets character from file pointer

Description

fgetc(resource $stream): string|false

Gets a character from the given file pointer.

Parameters

stream

All

Return Values

Returns a string containing a single character read from the file pointed to by stream. Returns false on EOF.

Falseproblem

Examples

A fgetc() example

php
<?php
$fp = fopen('somefile.txt', 'r');
if (!$fp) {
    echo 'Could not open file somefile.txt';
}
while (false !== ($char = fgetc($fp))) {
    echo "$char\n";
}
?>

Notes Bin-safe

See Also

Source: reference/filesystem/functions/fgetc.xml · from the official PHP manual (php/doc-en)