Home >Backend Development >PHP Tutorial >How to read data from csv file in php and output it to the web page, _PHP tutorial
The example in this article describes how php reads data from a csv file and outputs it to a web page. Share it with everyone for your reference. The specific implementation method is as follows:
<?php $fp = fopen('sample.csv','r') or die("can't open file"); print "<table>\n"; while($csv_line = fgetcsv($fp)) { print '<tr>'; for ($i = 0, $j = count($csv_line); $i < $j; $i++) { print '<td>'.htmlentities($csv_line[$i]).'</td>'; } print "</tr>\n"; } print '</table>\n'; fclose($fp) or die("can't close file"); ?>
I hope this article will be helpful to everyone’s PHP programming design.