php如何解析csv数据并输出?本文主要介绍了php从csv文件读取数据并输出到网页的方法,涉及php中fgetcsv函数及数组遍历的使用,希望对大家有所帮助
本文实例讲述了php从csv文件读取数据并输出到网页的方法。分享给大家供大家参考。具体实现方法如下:
<?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");
?>
相关推荐:
phpexcel如何导入excel处理大数据的代码实例
php fgetcsv() 函数语法参数enclosure详解
fgetcsv函数读取csv文件中文字符串的问题
以上就是关于php解析csv数据并输出的详细内容。