How does php parse csv data and output it? This article mainly introduces the method of php reading data from csv files and outputting it to the web page, involving the use of fgetcsv function and array traversal in php. I hope it will be helpful to everyone.
The example of this article describes how php reads data from csv files. How to get data and output 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"); ?>
Related recommendations:
phpexcel How to import excel to process big data Code example
php fgetcsv() function syntax parameter enclosure detailed explanation
fgetcsv function reading The problem of getting Chinese strings from csv files
The above is the detailed content of About php parsing csv data and outputting it. For more information, please follow other related articles on the PHP Chinese website!