0
0
PHPprogramming~5 mins

File open modes in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A'x'
B'w'
C'a'
D'r'
What does the 'r+' mode allow you to do?
ARead only, starting at the end
BWrite only, truncating the file
CAppend only, writing at the end
DRead and write, starting at the beginning of the file
If you want to add data to the end of a file without deleting existing content, which mode should you use?
A'a'
B'r'
C'w'
D'x'
What does the 'b' flag do when opening a file in PHP?
AOpens the file in backup mode
BOpens the file in buffered mode
COpens the file in binary mode
DOpens the file in basic mode
Which mode will open a file for reading only and fail if the file does not exist?
A'w'
B'r'
C'a'
D'x'
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.