You are writing a PHP script and you need to create a file and write to it. How would you do this?
- Use the fopen() function with 'w' mode to create the file and obtain a file handle, then use the fwrite() function to write content to the file.
- Use the file_put_contents() function to create the file and write content to it.
- Use the touch() function to create the file, then use the fwrite() function to write content to the file.
- Use the mkdir() function to create a directory instead of a file.
To create a file and write to it in PHP, you would use the fopen() function with 'w' mode to create the file and obtain a file handle. Then, you can use the fwrite() function with the file handle to write content to the file. This allows you to create a file if it doesn't exist and write data to it. Proper file handling includes opening, writing, and closing the file after you are done.
Loading...
Related Quiz
- Which of the following are common uses of the json_encode() and json_decode() functions in PHP?
- The + operator in PHP is used for ______.
- What is the difference between mysqli_fetch_object() and mysqli_fetch_array()?
- The $_POST superglobal in PHP is an associative array.
- How can you call a user-defined function in PHP using a string variable?