Home >Backend Development >PHP Tutorial >How to read data from csv file and output to web page_PHP tutorial

How to read data from csv file and output to web page_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:051018browse

How php reads data from a csv file and outputs it to the web page

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969342.htmlTechArticleHow php reads data from a csv file and outputs it to the web page. This example describes how php reads data from a csv file. And output to the web page. Share it with everyone for your reference. Specific implementation method...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn