0
0
PHPprogramming~10 mins

File pointer manipulation 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.

PHP
<?php
$file = fopen('example.txt', '[1]');
?>
Drag options to blanks, or click blank then click option'
Ax
Bw
Ca
Dr
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which opens the file for writing and truncates it.
Using 'a' which opens the file for appending.
2fill in blank
medium

Complete the code to move the file pointer to the beginning of the file.

PHP
<?php
rewind([1]);
?>
Drag options to blanks, or click blank then click option'
A$handle
B$fp
C$file
D$stream
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that was not defined.
Passing a string instead of the file resource.
3fill in blank
hard

Fix the error in the code to move the file pointer 10 bytes from the start.

PHP
<?php
fseek([1], 10, SEEK_SET);
?>
Drag options to blanks, or click blank then click option'
A$file
B$fp
C$stream
D$handle
Attempts:
3 left
💡 Hint
Common Mistakes
Using an undefined variable.
Passing a string instead of the file resource.
4fill in blank
hard

Fill both blanks to read 20 bytes from the file starting at byte 5.

PHP
<?php
fseek([1], 5, SEEK_SET);
$content = fread([2], 20);
?>
Drag options to blanks, or click blank then click option'
A$file
B$fp
C$handle
D$stream
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for fseek and fread.
Using undefined variables.
5fill in blank
hard

Fill all three blanks to move the pointer 15 bytes from the end and read 10 bytes.

PHP
<?php
fseek([1], [2], [3]);
$data = fread([1], 10);
?>
Drag options to blanks, or click blank then click option'
A$file
B-15
CSEEK_END
DSEEK_SET
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive offset instead of negative.
Using SEEK_SET instead of SEEK_END.
Using different variables for fseek and fread.