9 File Handling And Data Formats

Web Technology II · Unit 9

File Handling and Data Formats

Exam-focused notes for File Handling and Data Formats (Web Technology II, BIT301): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.

What this unit covers

  • File reading operations
  • File writing operations
  • File operations and I/O
  • JSON file parsing and reading
  • CSV file parsing and processing
  • File content display

CSV file parsing and processing

20825 marks

Write a program to parse a CSV file and display the content in the file. [5]

A CSV file stores a table as plain text: one record per line, with the fields of a record separated by commas and any field that itself contains a comma or a quote wrapped in double quotes. Because of that quoting rule a CSV line cannot be split reliably by...

Full solved answer →
05 marks

Write a PHP program to parse a CSV file. [5]

A CSV file is plain text in which every line is one record and the fields inside a line are separated by a delimiter, normally a comma. PHP opens such a file with fopen() and then pulls one record at a time with fgetcsv(), which returns the fields of that r...

Full solved answer →

File reading operations

20815 marks

Write a PHP program to read a file. [5]

--- There are several ways to read a file in PHP. Below are the common approaches: --- --- --- --- Function Description ------ fopen($file, "r") Opens a file in read mode fgets($file) Reads one line from the file feof($file) Returns true if end of file is r...

Full solved answer →

File writing operations

20805 marks

Write a PHP program to write on a file. [5]

PHP provides built-in functions to handle file operations. The most common approach uses fopen(), fwrite(), and fclose() functions. --- Function Description ----------------------- fopen(filename, mode) Opens a file; returns a file handle fwrite(handle, str...

Full solved answer →

JSON file parsing and reading

20795 marks

For the following JSON file named BIT.JSON, write a PHP program to read information from this JSON file: {Name: "Gunadi", Email: "[email protected]", Dob: "January 1", Age: 30} [5]

The listing in the question is written as a JavaScript object literal, with the property names bare: That is not valid JSON, and jsondecode() rejects it and returns null, because the JSON grammar requires every key to be a double quoted string. The file BIT...

Full solved answer →