PHP - File HandlingWhich of the following is the correct way to open a CSV file for writing in PHP?A$file = fopen('data.csv', 'r');B$file = fopen('data.csv', 'rw');C$file = fopen('data.csv', 'w');D$file = fopen('data.csv', 'x');Check Answer
Step-by-Step SolutionSolution:Step 1: Understand fopen modesMode 'w' opens a file for writing and truncates it if it exists, perfect for writing CSV files.Step 2: Check other modes'r' is read-only, 'rw' is invalid, 'x' creates a new file but fails if it exists.Final Answer:$file = fopen('data.csv', 'w'); -> Option CQuick Check:Open file for writing = 'w' mode [OK]Quick Trick: Use 'w' mode in fopen() to write files [OK]Common Mistakes:Using 'r' mode when intending to writeUsing invalid mode 'rw'Using 'x' which fails if file exists
Master "File Handling" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Array Functions - Array unique and flip - Quiz 1easy Interfaces and Traits - Trait declaration and usage - Quiz 1easy Interfaces and Traits - Why traits are needed - Quiz 11easy Interfaces and Traits - Why traits are needed - Quiz 12easy Sessions and Cookies - Session vs cookie decision - Quiz 15hard Sessions and Cookies - How cookies work - Quiz 3easy String Functions - Case conversion functions - Quiz 13medium Superglobals and Web Context - Form handling execution flow - Quiz 14medium Superglobals and Web Context - Form handling execution flow - Quiz 5medium Superglobals and Web Context - $_FILES for file uploads - Quiz 8hard