fgetc()

fgetc() — Gets character from file pointer.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

fgetc(resource $stream): string|false

Parameters

ParameterTypeWhat it takes
$streamresourceThe file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).

Return value

Returns a string containing a single character read from the file pointed to by stream. Returns false on EOF. This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Example

A runnable snippet:

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

See also

fread(), fopen(), popen(), fsockopen(), fgets()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page fgetc() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.