0
0
PHPprogramming~10 mins

File open modes in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aw
Br
Ca
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which opens the file for writing and truncates it.
2fill in blank
medium

Complete 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'
Aw
Br+
Ca
Dr
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'a' which appends instead of truncating.
3fill in blank
hard

Fix 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'
Aw
Br
Ca
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which overwrites the file instead of appending.
4fill in blank
hard

Fill 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'
Ar
B+
Cw
Da
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w+' which truncates the file.
5fill in blank
hard

Fill 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'
Ar
B+
Cw
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r+' which does not create the file if missing.