PHP - Function fgetc()


Advertisements


Syntax

string fgetc ( resource $handle );

Definition and Usage

Gets a character from the given file pointer.

Parameters

Parameter Description
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

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
   $fp = fopen('example.txt', 'r');
   
   if (!$fp) {
      echo 'Could not open file somefile.txt';
   }
   
   while (false !== ($char = fgetc($fp))) {
      echo "$char\n";
   }
?>

php_function_reference.htm

Advertisements