Menu Home

fgetc

osbo.com | PHP | Functions | fgetc

Gets character from file pointer

Syntax

fgetc ( resource $handle ) : string

Parameters

handle

The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).

Return

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

Examples

<?

$filename = $_SERVER["DOCUMENT_ROOT"] . "/assets/txt/file.txt";
$mode = "r";

$handle = fopen($filename, $mode);

    while (!feof($handle))
    {
        $return = fgetc($handle);

        echo "$return\n";
    }

fclose($handle);

?>
H
e
l
l
o

PHP