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//from  w  ww  . ja  v  a  2  s . co  m
$file = fopen("data.txt","r");
echo fgetc($file);
fclose($file);
?>

Example 2

Read file character by character:


<?php/* w  w w .j a  va 2s. c o  m*/
$file = fopen("data.txt","r");

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

fclose($file);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions