PHP - Function fgetc()


Advertisements


Syntax

string fgetc ( resource $handle );

Definition and Usage

It gets a character from the given file pointer.

Parameters

Sr.No Parameter & Description
1

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 Value

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

Example

Following is the usage of this function −

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

php_function_reference.htm

Advertisements