You are tasked with creating a PHP function that accepts a filename, opens the file, prints its contents, and then closes the file. How would you approach this task?

  • Use the fopen() function to open the file, read its contents using fread() or other file reading functions, print the contents, and then close the file using fclose()
  • Use the readfile() function to directly output the file contents, and then close the file using fclose()
  • Use the file_get_contents() function to read the entire file into a string, print the contents, and then close the file using fclose()
  • Use the file() function to read the file line by line into an array, print the contents, and then close the file using fclose()
You can create a PHP function that accepts a filename. Inside the function, you would use fopen() to open the file, fread() or other file reading functions to read its contents, print the contents as desired, and then close the file using fclose(). This ensures proper file handling and cleanup after printing the contents.
Add your answer
Loading...

Leave a comment

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