readContactCSV.php

Source of readContactCSV.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>readContactCSV.php</title>
</head>
<body>
<h1>Contacts</h1>
<div>
<?php

print <<< HERE

<table border = "1">
  <tr>
    <th>First</th>
    <th>Last</th>
    <th>email</th>
    <th>phone</th>
  </tr>

HERE;

$data = file("contacts.csv");
foreach ($data as $line){
  $lineArray = explode("\t", $line);
   
  list($fName, $lName, $email, $phone) = $lineArray;
  print <<< HERE
    <tr>
      <td>$fName</td>
      <td>$lName</td>
      <td>$email</td>
      <td>$phone</td>
    </tr>

HERE;
} // end foreach

//print the bottom of the table
print "</table> \n";

?>
</div>
    
</body>
</html>