Bird
0
0

Which of the following is the correct syntax to open a file for reading in PHP?

easy📝 Syntax Q3 of 15
PHP - File Handling
Which of the following is the correct syntax to open a file for reading in PHP?
Afile_open('data.txt', 'r');
B$file = fopen('data.txt', 'r');
C$file = open('data.txt', 'read');
Dopen_file('data.txt', 'read');
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct PHP function for opening files

    PHP uses fopen() to open files with a filename and mode string.
  2. Step 2: Recognize correct mode for reading

    The mode 'r' means open for reading only.
  3. Final Answer:

    $file = fopen('data.txt', 'r'); -> Option B
  4. Quick Check:

    fopen + 'r' = open for reading [OK]
Quick Trick: Use fopen(filename, 'r') to open files for reading [OK]
Common Mistakes:
  • Using non-existent functions like open()
  • Using wrong mode strings like 'read'
  • Confusing fopen with file_open

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes