Recall & Review
beginner
What PHP function is commonly used to read a CSV file line by line?
The
fgetcsv() function reads a line from an open file and parses it as CSV, returning an array of fields.Click to reveal answer
beginner
How do you open a file for writing CSV data in PHP?
Use
fopen() with the mode 'w' to open a file for writing. This will create the file if it doesn't exist or overwrite it if it does.Click to reveal answer
beginner
Which PHP function writes an array as a CSV line to a file?
The
fputcsv() function takes an array and writes it as a CSV formatted line to an open file.Click to reveal answer
beginner
What is the purpose of closing a file after reading or writing CSV data?
Closing a file with
fclose() frees system resources and ensures all data is properly saved and no corruption occurs.Click to reveal answer
intermediate
How can you handle CSV files with different delimiters in PHP?
Both
fgetcsv() and fputcsv() accept an optional delimiter parameter to specify characters like semicolon ; instead of comma ,.Click to reveal answer
Which function reads a CSV line into an array in PHP?
✗ Incorrect
fgetcsv() reads a line from a file and parses it as CSV.What mode should you use with
fopen() to write a new CSV file?✗ Incorrect
'w' mode opens the file for writing and overwrites existing content.
Which function writes an array as a CSV line to a file?
✗ Incorrect
fputcsv() formats an array as CSV and writes it to a file.Why should you always close a file after reading or writing CSV data?
✗ Incorrect
Closing a file with
fclose() ensures data integrity and frees resources.How can you read a CSV file that uses semicolons instead of commas?
✗ Incorrect
fgetcsv() allows specifying a custom delimiter like ';' to parse CSV correctly.Explain the steps to read a CSV file line by line in PHP and process each row.
Think about opening, reading, looping, and closing the file.
You got /4 concepts.
Describe how to write multiple rows of data to a CSV file in PHP.
Remember to open, write each row, then close.
You got /3 concepts.