PHP Manual
Prev |  | Next

# fread

fread -- Binary-safe file read

## Description

`string fread`(int fp, int length);

fread() reads up to `length` bytes from the file pointer referenced by `fp`. Reading stops when `length` bytes have been read or EOF is reached, whichever comes first.

      1
      2 // get contents of a file into a string
      3 $filename = "/usr/local/something.txt";
      4 $fd = fopen ($filename, "r");
      5 $contents = fread ($fd, filesize ($filename));
      6 fclose ($fd);
      7

See also fwrite(), fopen(), fsockopen(), popen(), fgets(), fgetss(), file(), and fpassthru().

Prev | Home | Next
fputs | Up | fseek