The fgets() function reads a single line from a file pointer in PHP. It stops reading when it encounters a newline character (\n) or reaches the end of the file.
4.
How do you close a file after reading from it in PHP?
fclose() is used to close an open file pointer in PHP. It's important to close files after reading from them to free up system resources and prevent memory leaks.
5.
Which mode should be used to open a file for writing in PHP?
The 'w' mode is used to open a file for writing in PHP. It truncates the file to zero length or creates a new file if it doesn't exist. Existing file contents are overwritten.
6.
What does the 'a' mode do when opening a file in PHP?
When opening a file in 'a' mode, PHP appends data to the end of the file if it exists or creates a new file if it doesn't exist. Existing file contents remain unchanged.
7.
Which function is used to write data to a file in PHP?