Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

fread()

Example

Open a file and read 10 bytes from it:

<?php
$file = fopen(“test.txt”,“r”);
fread($file,“10”);
fclose($file);
?>

Definition and Usage

Fread() retrieves data from an open file.

Upon reaching the given length or the end of the file, whichever occurs first, the function will terminate.Reword

Syntax

fread(filelength)

Parameter Values

 

Parameter

Description

file

Essential. indicates the open file that will be read.

length

Essential. indicates the most bytes that can be read.

Technical Details

Return Value:

The read string; if it fails, FALSE

PHP Version:

4.0+

Binary Safe:

Yes

More Examples

Example

Go through the full file:Reword

<?php
$file = fopen(“test.txt”,“r”);
fread($file,filesize(“test.txt”));
fclose($file);
?>