Home >Backend Development >PHP Tutorial >About php parsing csv data and outputting it

About php parsing csv data and outputting it

*文
*文Original
2017-12-25 17:25:102914browse

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(&#39;sample.csv&#39;,&#39;r&#39;) or die("can&#39;t open file");
print "<table>\n";
while($csv_line = fgetcsv($fp)) {
  print &#39;<tr>&#39;;
  for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
    print &#39;<td>&#39;.htmlentities($csv_line[$i]).&#39;</td>&#39;;
  }
  print "</tr>\n";
}
print &#39;</table>\n&#39;;
fclose($fp) or die("can&#39;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!

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