Home >Backend Development >PHP Tutorial >How to read data from csv file and output to web page_PHP tutorial
The example in this article describes the method of php reading data from the csv file and outputting it to the 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.