O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading in Files

Reading in files is almost the same as writing to files—just the opposite. When we were writing to files earlier, we passed a string as a parameter that contained the data in the file. When we read in files, the reading function returns a string that we can manipulate for our purposes.

fread()

So what is the reading function, then? If you’ve been paying attention, you can probably guess the name: fread(). Take a look at the function declaration:

fread($handle, $lengthInBytes)

Both of these parameters are required. The first parameter is the handle to the file we retrieved by using fopen(). The second parameter is the number of bytes you wish to retrieve. fread() only works for pages that have been opened for reading access. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required