Current Location: Home> Function Categories> fpassthru

fpassthru

All remaining data at the output file pointer
Name:fpassthru
Category:File system
Programming Language:php
One-line Description:Read data from the open file until EOF, and write the result to the output buffer.

Definition and usage

fpassthru() function outputs all remaining data at the file pointer.

This function reads the given file pointer to EOF from the current location and writes the result to the output buffer.

Example

Example 1

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

// Read the first line
fgets ( $file ) ;

// Send the rest of the file to the output cache
echo fpassthru ( $file ) ;

fclose ( $file ) ;
?>

Output:

 There are three lines in this file.
This is the last line.59

Note: 59 Indicates the number of characters passed.

Example 2

Dump the index page of the www server:

 <?php
$file = fopen ( "http://www.example.com" , "r" ) ;
fpassthru ( $file ) ;
?>

grammar

 fpassthru ( file )
parameter describe
file Required. Specifies the open file or resource to be read.

illustrate

If an error occurs, fpassthru() returns false. Otherwise fpassthru() returns the number of characters read from the file and passed to the output.

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