PHP fpassthru() Function
In this chapter you will learn:
- Definition for PHP fpassthru() Function
- Syntax for PHP fpassthru() Function
- Parameter for PHP fpassthru() Function
- Return for PHP fpassthru() Function
- Note on PHP fpassthru() Function
- Example - Send rest of the file to the output buffer
- Example - Dump index page of a www server
Definition
The fpassthru() function reads all data from the current position in an open file, until EOF, and writes the result to the output buffer.
Syntax
PHP fpassthru() Function has the following syntax.
fpassthru(file)
Parameter
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file or resource to read from |
Return
This function returns the number of characters passed or FALSE on failure.
Note
When using fpassthru() on a binary file on Windows, remember to open the file in binary mode.
Example
<?php//from j ava2s . c om
$file = fopen("test.txt","r");
fgets($file);// Read first line
echo fpassthru($file);// Send rest of the file to the output buffer
fclose($file);
?>
The code above generates the following result.
Example 2
Dump index page of a www server:
/*from jav a 2 s. c om*/
<?php
$file = fopen("http://www.google.com","r");
echo fpassthru($file);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP fprintf() Function
- Syntax for PHP fprintf() Function
- Parameter for PHP fprintf() Function
- Additional format
- Return for PHP fprintf() Function
- Related functions
- Example - Write some text to a text file named "test.txt"
- Example - Use of placeholders
- Example - Using printf() to demonstrate all possible format values
Home » PHP Tutorial » PHP File Functions