Questions: Question 6 Mark this question In PHP, what function is commonly used to create a new file and open it for writing, erasing the file's contents if it already exists, or creating a new file if it doesn't exist? fclose() fopen() fwrite() fread()

Question 6
Mark this question

In PHP, what function is commonly used to create a new file and open it for writing, erasing the file's contents if it already exists, or creating a new file if it doesn't exist?
fclose()
fopen()
fwrite()
fread()
Transcript text: Question 6 Mark this question In PHP, what function is commonly used to create a new file and open it for writing, erasing the file's contents if it already exists, or creating a new file if it doesn't exist? fclose() fopen() fwrite() fread()
failed

Solution

failed
failed

The answer is the second one (or B): fopen().

Explanation for each option:

  • fclose(): This function is used to close an open file pointer. It does not create or open a file for writing.
  • fopen(): This function is used to open a file or URL. When used with the mode 'w', it opens the file for writing, erasing the file's contents if it already exists, or creating a new file if it doesn't exist.
  • fwrite(): This function is used to write data to an open file pointer. It does not create or open a file.
  • fread(): This function is used to read data from an open file pointer. It does not create or open a file.

Summary: The fopen() function is commonly used in PHP to create a new file and open it for writing, erasing the file's contents if it already exists, or creating a new file if it doesn't exist.

Was this solution helpful?
failed
Unhelpful
failed
Helpful