Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function fgetc()


previous

Advertisements

Syntax

string fgetc ( resource $handle );

Definition and Usage

Gets a character from the given file pointer.

Paramters

ParameterDescription
handleThe 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";
}
?>

previous Printer Friendly

Advertisements


  

Advertisements