In this lesson our instructor talks about an introduction to the file I/O. First, he discusses File I/O, file permissions, fopen(), and file paths. Then he talks about file access modes, fopen() coding example, file pointers, fgets(), feof(), and fclose(). He also talks about trim () and a coding example. He ends the lesson with a homework challenge.
In order to read from or write to a file from PHP, the user account under which the PHP interpreter runs must
have the appropriate read/write permissions on the file, depending on the desired operation.
fopen() is used to open a file. You must specify whether you wish to open the file for reading,
writing, or both. This is done using the function's access mode parameter.
fopen() returns a file handle, which represents a connection to an opened file. The file
handle is a special PHP data type known as a resource.
File paths should always be specified using forward-slashes (/) as the path separator because it maximizes the
portability of your code.
Data in a file is accessed using a file pointer, which is a cursor used to keep track of the current character
being accessed in a file.
When opening a file with fopen() using ‘r’ as the access mode, the file
is opened for reading with the file pointer placed at the beginning of the file.
fgets() reads the contents of the current line of a file and advances the file pointer to the
beginning of the next line.
feof() returns TRUE if a file pointer’s current position is at the end of the
fclose() is used to close the connection to an open file by passing it the file handle of the open
trim() is used to strip any whitespace from the beginning or end of a string.
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.