fpassthru() function in PHP


The fpassthru() function reads from an open file, until EOF, and writes the result to the output buffer. It returns the number of characters read from the file pointer, otherwise if an error occurs, it returns FALSE.

Syntax

fpassthru(file_pointer):

Parameters

  • file_pointer − The file pointer must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).

Return

The fpassthru() function returns the number of characters read from the file pointer, otherwise if an error occurs, it returns FALSE.

Example

<?php
   $file_pointer = fopen("new.txt","r");
   fgets($file);
   echo fpassthru($file_pointer);
   fclose($file_pointer);
?>

The following is the output. The characters are 22.

Output

Demo text!!
This is it!22

Updated on: 24-Jun-2020

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements