Current Location: Home> Function Categories> fgetc

fgetc

Read characters from file pointer
Name:fgetc
Category:File system
Programming Language:php
One-line Description:Return characters from the opened file.

Definition and usage

The fgetc() function reads a character from the file pointer.

Example

Example 1

 <?php

$file = fopen ( "test.txt" , "r" ) ;
echo fgetc ( $file ) ;
fclose ( $file ) ;

?>

The output is similar:

 H

Example 2

 <?php

$file = fopen ( "test.txt" , "r" ) ;

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

fclose ( $file ) ;
?>

The output is similar:

 Hello, this is a test file.

grammar

 fgetc ( file )
parameter describe
file Required. Specify documents to be inspected.

illustrate

Returns a string containing a character obtained from the file pointed to by the file. If EOF is encountered, it returns false.

The file pointer must be valid and must point to a file that was successfully opened by fopen() or fsockopen() (but has not been closed fclose() ).

Similar Functions
Popular Articles