What function is used to read the contents of a file in PHP?
- readfile()
- file_get_contents()
- fread()
- include()
In PHP, the fread() function is used to read the contents of a file. It takes the file handle obtained from fopen() as the first parameter and the maximum number of bytes to read as the second parameter. This function returns the content of the file as a string. Alternatively, you can use file_get_contents() to read the entire file into a string or other file reading functions depending on your specific use case.
Loading...
Related Quiz
- What is the purpose of the str_replace() function in PHP?
- You need to store a collection of key-value pairs in your PHP script and then sort them based on the keys or values. How would you do this using an associative array?
- Which of the following are true about the break and continue statements in PHP?
- You are writing a PHP script and you need to store a list of items that can be accessed by their position in the list. How would you do this using an indexed array?
- How do you define a constructor in a PHP class?