Wednesday, January 20, 2016

PHP: Read a CSV file and dynamically create a HTML Table

PHP

<?php
      
       echo "<table class='arrTable'><tr><td colspan='4' class='subH td'><p align='center'>Warehouse Contact List</p></td></tr>";
      
       echo "<tr><td class='subH td'>Warehouse</td><td class='subH td'>Name</td><td class='subH td'>Ext.</td><td class='subH td'>Cell</td></tr>";
      
       $f=fopen("docs/Warehouse Contact List.csv", "r");
       while(($line=fgetcsv($f))!=false){
           echo "<tr>";
           foreach($line as $cell){
          
           echo "<td>".htmlentities($cell)."</td>";
          
           }
          
           echo "</tr>";
      }    
     
      fclose($f);
     
      echo "</table>";
       ?>

No comments:

Post a Comment