You have a PHP script and you need to read a file. How would you do this?
- open the file using fopen() and read its contents using fread()
- use the file_get_contents() function to read the entire file into a string
- use the file() function to read the file line by line into an array
- use the readfile() function to output the contents of the file directly
To read a file in a PHP script, you would typically open the file using the fopen() function to obtain a file handle. Then, you can use the fread() function to read the content of the file in chunks or specific byte sizes. Alternatively, you can use functions like file_get_contents() to read the entire file into a string or file() to read the file line by line into an array.
Loading...
Related Quiz
- The PHP interpreter executes comments as part of the script.
- You have an associative array in your PHP script and you're encountering issues with accessing or manipulating the elements. How would you debug this?
- An abstract class in PHP OOP is a class that cannot be instantiated and is meant to be extended by other classes.
- In a PHP do...while loop, where is the condition tested?
- Which of the following are common uses of functions in PHP?