Recall & Review
beginner
What does the 'r' mode do when opening a file in PHP?
The 'r' mode opens a file for reading only. The file pointer is placed at the beginning of the file. The file must exist.
Click to reveal answer
intermediate
Explain the difference between 'w' and 'a' modes in PHP file handling.
'w' mode opens a file for writing only and truncates the file to zero length or creates it if it doesn't exist. 'a' mode opens a file for writing only but places the file pointer at the end, preserving existing content and creating the file if it doesn't exist.
Click to reveal answer
intermediate
What happens if you open a file with 'x' mode in PHP?
'x' mode creates and opens a file for writing only. If the file already exists, the fopen() call will fail. It is used to avoid overwriting existing files.
Click to reveal answer
intermediate
What does the '+' symbol mean when added to a file open mode in PHP?
Adding '+' to a mode (like 'r+', 'w+', 'a+') opens the file for both reading and writing. The exact behavior depends on the base mode but allows you to read and write in the same file handle.
Click to reveal answer
beginner
What is the purpose of the 'b' mode in PHP file opening?
The 'b' mode stands for binary mode. It is used to open files in binary mode instead of text mode, which is important on Windows systems to prevent automatic translation of newline characters.
Click to reveal answer
Which file open mode in PHP will create a new file but fail if the file already exists?
✗ Incorrect
The 'x' mode creates a new file for writing and fails if the file already exists.
What does the 'r+' mode allow you to do?
✗ Incorrect
'r+' opens the file for both reading and writing, with the pointer at the start.
If you want to add data to the end of a file without deleting existing content, which mode should you use?
✗ Incorrect
'a' mode opens the file for writing and places the pointer at the end, preserving existing content.
What does the 'b' flag do when opening a file in PHP?
✗ Incorrect
'b' opens the file in binary mode, important for Windows systems to avoid newline translation.
Which mode will open a file for reading only and fail if the file does not exist?
✗ Incorrect
'r' mode opens a file for reading only and requires the file to exist.
Describe the main differences between 'r', 'w', and 'a' file open modes in PHP.
Think about whether the file pointer starts at the beginning or end and if the file is created or erased.
You got /3 concepts.
Explain how adding '+' to a file open mode changes its behavior in PHP.
Consider how you can both read and write with the same file pointer.
You got /3 concepts.