Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

get data from csv file in php and print in table

<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1>DISPLAY DATA PRESENT IN CSV</h1>
        <h3>Student data</h3>
  
        <?php
        echo "<html><body><center><table>

";
  
        // Open a file
        $file = fopen("a.csv", "r");
  
        // Fetching data from csv file row by row
        while (($data = fgetcsv($file)) !== false) {
  
            // HTML tag for placing in row format
            echo "<tr>";
            foreach ($data as $i) {
                echo "<td>" . htmlspecialchars($i) 
                    . "</td>";
            }
            echo "</tr> 
";
        }
  
        // Closing the file
        fclose($file);
  
        echo "
</table></center></body></html>";
        ?>
    </center>
</body>
  
</html>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #data #csv #file #php #print #table
ADD COMMENT
Topic
Name
7+1 =