Complete the code to open a file for writing.
<?php $file = fopen('example.txt', '[1]'); ?>
The mode 'w' opens the file for writing and truncates the file to zero length or creates it if it doesn't exist.
Complete the code to write the string 'Hello World' to the file using fwrite.
<?php $file = fopen('example.txt', 'w'); fwrite([1], 'Hello World'); fclose($file); ?>
The variable $file holds the file handle returned by fopen, which is needed by fwrite.
Fix the error in the code to write 'Data' to a file using file_put_contents.
<?php [1]('data.txt', 'Data'); ?>
The correct function to write data to a file in one call is file_put_contents.
Fill both blanks to write 'Hello' to 'greeting.txt' and then close the file.
<?php $file = fopen('greeting.txt', '[1]'); fwrite($file, '[2]'); fclose($file); ?>
Use 'w' mode to open the file for writing and 'Hello' as the string to write.
Fill all three blanks to write the uppercase filename, the content variable, and the comparison operator in the code.
<?php $filename = 'log.txt'; $content = 'Log entry'; if (strlen($content) [3] 0) { file_put_contents([1], [2]); } ?>
Use $filename as the file name, $content as the data to write, and '>' to check if content length is greater than zero.