PHP Programming              Exercise: File IO(more)                 Spring 2015


0. Given a form to collect category, id, name, quantity and price, code a PHP
   script to obtain form values and assign them to local variables.


1. Invoke fopen() for appending('a+') to a file named hearth.txt and assign the
   return value to a file pointer named $fp. Example data:
   tool      10387 Tool Set       11 54.99
   fuel      11597 Long Matches   02 05.49
   fuel      11879 Color Cones    10 39.95
   fuel      12390 Fatwood        08 46.99
   container 12985 Hooplog Rack   11 29.99
   container 13012 Wood sling     15 49.95
   container 13042 Fatwood bucket 09 39.99
   container 13119 Oval Tub       11 89.99
   container 52396 Boot Tray      06 46.95
   fixture   87537 Mitten Tree    04 30.99

2. Output the data with fixed-length fields or with comma-separators (csv):   
   a. Apply the fprintf function to output data with a fixed-format layout with
      category(string 0-8), id(int 10-14), name(string 16-29), quantity (31-32),
      price (float 34-38, 2 dec places), plus "newline".
   
   
  
   b. Or, use fputcsv($fp, $hearthArray);



3. After the output of one or more lines to hearth.txt, invoke a script to open
   hearth.txt for reading('r') and retrieve it's contents. For line-by-line, 
   assign each value returned by fgets($fp) to string variable $hearthLine).

   


4. Use the function substr ($fullStringName, $nameStart, $nameLength) to
   extract the field components of $hearthLine and assign to $category, $id, 
   $name, $quantity, and $price respectively. Print these items.




5. Open the file "hearth.csv" for reading and and assign the return value to 
   $fp. Example data for hearth.csv:
   tool,10387,Tool Set,11,54.99
   fuel,11597,Long Matches,02,05.49
   fuel,11879,Color Cones,10,39.95
   fuel,12390,Fatwood,08,46.99
   container,12985,Hooplog Rack,11,29.99
   container,13012,Wood sling,15,49.95
   container,13042,Fatwood bucket,09,39.99
   container,13119,Oval Tub,11,89.99
   container,52396,Boot Tray,06,46.95
   fixture,87537,Mitten Tree,04,30.99
    
    
6. For the hearth file "hearth.csv" (delimited with commas) use the fgetcsv
   function to input each line of data. Assign the components to $category, $id, 
   $name, $quantity and $price then print and close files.