This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “File System and PHP”.
1. The filesize() function returns the file size in ___________
a) bits
b) bytes
c) kilobytes
d) gigabytes
View Answer
Explanation: The function filesize() returns the size of the specified file and it returns the file size in bytes on success or FALSE on failure.
2. Which one of the following PHP function is used to determine a file’s last access time?
a) fileltime()
b) filectime()
c) fileatime()
d) filetime()
View Answer
Explanation: The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE on error.
3. Which one of the following function is capable of reading a file into an array?
a) file()
b) arrfile()
c) arr_file()
d) file_arr()
View Answer
Explanation: The function file() will read the entire file into an array.
4. Which one of the following function is capable of reading a file into a string variable?
a) file_contents()
b) file_get_contents()
c) file_content()
d) file_get_content()
View Answer
Explanation: The function file_get_contents() reads a file into a string. This is the preferred way to read the contents of a file into a string as it will use memory mapping techniques.
5. Which one of the following function is capable of reading a specific number of characters from a file?
a) fgets()
b) fget()
c) fileget()
d) filegets()
View Answer
Explanation: The function fgets() will return a line from an open file. This stops returning on a new line, at the specified length, or at EOF, whichever comes first. Its prototype is string fgets(resource handle [, int length]). If the optional length parameter is omitted, 1024 character is assumed.
6. Which one of the following function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?
a) fgetsh()
b) fgetsp()
c) fgetsa()
d) fgetss()
View Answer
Explanation: The function fgetss() returns a line, with HTML and PHP tags removed, from an open file. This function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input.
7. Which one of the following function outputs the contents of a string variable to the specified resource?
a) filewrite()
b) fwrite()
c) filewrites()
d) fwrites()
View Answer
Explanation: The function fwrite() writes to an open file. This will stop at the end of the file or when it reaches the specified length, whichever comes first.
8. Which function sets the file filename last-modified and last-accessed times?
a) sets()
b) set()
c) touch()
d) touched()
View Answer
Explanation: The function touch() will set the access and modification time of the specified file. Syntax is touch(filename, time, atime).
9. Which function is useful when you want to output the executed command result?
a) out_cmm()
b) out_system()
c) cmm()
d) system()
View Answer
Explanation: The function system() in PHP is same as the C version of the function as in that it executes the given command and outputs the result. This function also tries to automatically flush the web server’s output buffer after each line of output if PHP is running as a server module.
10. Which one of the following function reads a directory into an Array?
a) scandir()
b) readdir()
c) scandirectory()
d) readdirectory()
View Answer
Explanation: It returns an array consisting of files and directories found in directory or returns FALSE on error.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Apply for Programming Internship
- Check PHP Books
- Check Information Technology Books
- Practice Programming MCQs
- Practice MCA MCQs