PHP - File HandlingWhich 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');Check Answer
Step-by-Step SolutionSolution:Step 1: Identify correct PHP function for opening filesPHP uses fopen() to open files with a filename and mode string.Step 2: Recognize correct mode for readingThe mode 'r' means open for reading only.Final Answer:$file = fopen('data.txt', 'r'); -> Option BQuick 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
Master "File Handling" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Array Functions - Array walk function - Quiz 1easy Error and Exception Handling - Finally block behavior - Quiz 1easy Error and Exception Handling - Try-catch execution flow - Quiz 10hard Inheritance and Polymorphism - Why inheritance is needed - Quiz 4medium Interfaces and Traits - Multiple interface implementation - Quiz 12easy Interfaces and Traits - Trait declaration and usage - Quiz 3easy Interfaces and Traits - Interface declaration and implementation - Quiz 14medium Sessions and Cookies - Starting and using sessions - Quiz 2easy Superglobals and Web Context - Form handling execution flow - Quiz 11easy Superglobals and Web Context - $_POST for form submissions - Quiz 1easy