English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP fgetc() Function Usage and Example

PHP Filesystem Reference Manual

The fgetc() function can return a single character from an open file and obtain the character from the given file pointer.

Syntax

string fgetc ( resource $handle )

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

This function is very slow for processing very large files, so it cannot be used for processing large files. If you need to sequentially read a character from a large file, please use the fgets() function to sequentially read a line of data, and then use the fgetc() function to sequentially process the line data.

Example1

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

Output Result

n

Example2

<?php
   $file = fopen("/PhpProject/sample.txt", "r");
   while(! feof($file)) {
      echo fgetc($file);
   }
   fclose($file);
?>

Output Result

oldtoolbag.com

PHP Filesystem Reference Manual