Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a file for reading only.
PHP
<?php $file = fopen('example.txt', '[1]'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which opens the file for writing and truncates it.
✗ Incorrect
The mode 'r' opens the file for reading only.
2fill in blank
mediumComplete the code to open a file for writing and truncate it if it exists.
PHP
<?php $file = fopen('example.txt', '[1]'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'a' which appends instead of truncating.
✗ Incorrect
The mode 'w' opens the file for writing and truncates it if it exists.
3fill in blank
hardFix the error in the code to open a file for appending.
PHP
<?php $file = fopen('example.txt', '[1]'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which overwrites the file instead of appending.
✗ Incorrect
The mode 'a' opens the file for appending, writing data at the end.
4fill in blank
hardFill both blanks to open a file for reading and writing without truncating.
PHP
<?php $file = fopen('example.txt', '[1][2]'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w+' which truncates the file.
✗ Incorrect
The mode 'r+' opens the file for reading and writing without truncating it.
5fill in blank
hardFill all three blanks to open a file for writing and reading, creating it if it doesn't exist.
PHP
<?php $file = fopen('example.txt', '[1][2][3]'); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r+' which does not create the file if missing.
✗ Incorrect
The mode 'x+' opens the file for writing and reading, creates it if it doesn't exist.