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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *