PHP » I/O » fread()

Syntax:
string fread(int file, int length)
file
File handle of the file to read from.
length
Number of bytes to read.

Reads from a file.

The fread() function reads a number of bytes from a file and returns them as a string.

Examples

Code:
<?php

$filename = "log.txt";

$logfile = fopen($filename, "r");
$data = fread($logfile, filesize($filename));
print nl2br($data);

?>
Output:
Sample code running
Sample code running
Sample code running
Sample code running
Explanation:

The code prints the contents of a log file to the browser. Since the log file contains new line characters that will not show in a web browser, nl2br() is used to convert them to html tags.

See Also: