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.
Loading...
Related Quiz
- The is_numeric() function in PHP checks if a variable is a(n) ______.
- To access an element of an indexed array in PHP, you use the name of the array followed by the ______ of the element in square brackets.
- You need to use the $this keyword in your PHP script. How would you do this?
- You need to access server-specific information in your PHP script. How would you do this using the $_SERVER superglobal?
- A function in PHP is a block of code that can be _______ when required.