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");
?>相关推荐:
php fgetcsv() 函数语法参数enclosure详解
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号