PHP 7 fread() Function
❮ PHP Filesystem ReferenceExample
Read 10 bytes from an open file:
<?php
$file = fopen("test.txt","r");
fread($file,"10");
fclose($file);
?>
Run Example »Definition and Usage
The fread() reads from an open file.
The function will stop at the end of the file or when it reaches the specified length, whichever comes first.
Syntax
fread(file, length)
Parameter | Description |
---|---|
file | Required. Specifies the open file to read from |
length | Required. Specifies the maximum number of bytes to read |
Technical Details
Return Value: | The read string, FALSE on failure |
---|---|
PHP Version: | 4.0+ |
Binary Safe: | Yes |
More Examples
Example
Read entire file:
<?php
$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>
Run Example »
❮ PHP Filesystem Reference