Web Application Development MCQs with Answers
Practice important Web Application Development MCQs with answers and explanations.
Multiple Choice Questions
Q151: Fill in the blank: To read a single line from a file, use the _______ function.
- A: fwrite()
- B: fgets()
- C: fread()
- D: feof()
View Answer
B
Q152: What function is used to output the contents of a file line by line until end-of-file?
- A: fopen()
- B: fclose()
- C: fgets() and feof()
- D: fread()
View Answer
C
Q153: Fill in the blank: To handle files carefully in PHP, avoid _______.
- A: editing the wrong file
- B: creating files
- C: reading files
- D: deleting files
View Answer
A
Q154: Which PHP function should be used to handle file reading and writing operations with more options?
- A: readfile()
- B: fopen()
- C: fgetc()
- D: fclose()
View Answer
B
Q155: Fill in the blank: The fread() function requires two parameters: the file name and the _______.
- A: file mode
- B: maximum number of bytes to read
- C: file pointer
- D: file content
View Answer
B
Q156: What is a common error to avoid when manipulating files in PHP?
- A: Reading a file
- B: Opening a file
- C: Editing the wrong file
- D: Using the correct file mode
View Answer
C
Q157: What function is used to create a file in PHP?
- A: fopen()
- B: fclose()
- C: fwrite()
- D: unlink()
View Answer
A
Q158: If you open a file using fopen() in PHP with mode "w", what happens to the existing data in the file?
- A: Data is appended
- B: Data is erased
- C: Data is preserved
- D: Data is encrypted
View Answer
B
Q159: Which PHP function is used to write data into a file?
- A: fwrite()
- B: fopen()
- C: fclose()
- D: file_exists()
View Answer
A
Q160: How do you specify a file to be opened for writing in PHP?
- A: fopen("file.txt", "r")
- B: fopen("file.txt", "w")
- C: fopen("file.txt", "a")
- D: fopen("file.txt", "x")
View Answer
B