PHP Tutorial - PHP fgetc() Function






Definition

The fgetc() function returns a single character from an open file.

Syntax

PHP fgetc() Function has the following syntax.

fgetc(file)

Parameter

ParameterIs RequiredDescription
fileRequired.File to check

Return

PHP fgetc() Function returns a single character from an open file.

Example 1


<?php
$file = fopen("data.txt","r");
echo fgetc($file);
fclose($file);
?>




Example 2

Read file character by character:


<?php
$file = fopen("data.txt","r");

while (! feof ($file)){
  echo fgetc($file);
}

fclose($file);
?>