php从csv文件读取数据并输出到网页的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了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程序设计有所帮助。

相关文章

php实现XML和数组的相互转化功能示例

本文实例讲述了php实现XML和数组的相互转化功能。分享给大家供大家参考,具体如下: 数组转化为xml: function arrtoxml($arr,$dom=0,$item=0)...

php apache开启跨域模式过程详解

apaceh 配置: <VirtualHost *:80> ServerAdmin xxx@qq.com DocumentRoot "C:/htdocs/demo...

PHP判断浏览器、判断语言代码分享

PHP编程中经常需要用到一些服务器的一些资料,特把$_SERVER的详细参数整理下,方便以后使用。 判断浏览器类型 //判断类型 <?php if(strpos($...

PHP使用PHPexcel导入导出数据的方法

本文实例讲述了PHP使用PHPexcel导入导出数据的方法。分享给大家供大家参考,具体如下: 导入数据: <?php error_reporting(E_ALL); /...

基于PHP对XML的操作详解

<?php      $xml = simplexml_load_file('example.xml');  &nbs...