澳门太阳娱乐集团官网-太阳集团太阳娱乐登录

【太阳集团太阳娱乐登录】php将数组输出为.csv文
分类:脚本专栏

<?php $sales = array(array(    1,'pj','nan'    ),array(    2,'lsm','nv'    ),array(    3,'ls','na'    ));$salesFile = fopen("salesFile.csv","w") or die("Can't open salesFile.csv!");foreach ($sales as $sales_line) {    # code...    if(fputcsv($salesFile, $sales_line)===false){        die("Can't write CSV line");    }}fclose($salesFile) or die("Can't close saleFile.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");
?>

太阳集团太阳娱乐登录,输出的文件为同级目录下的salesFile.csv文件

<?php error_reporting( E_ALL );ini_set( 'display_errors' , 'On' );$sales = array(array(    1,'pj','nan'    ),array(    2,'lsm','nv'    ),array(    3,'ls','na'    ));$salesFile = fopen("php://output","w");foreach ($sales as $sales_line) {    # code...    if(fputcsv($salesFile, $sales_line)===false){        die("Can't write CSV line");    }}fclose($salesFile); ?>

输出到php://output输出流

<?php error_reporting( E_ALL );ini_set( 'display_errors' , 'On' );$salesFile = fopen("salesFile.csv","r") or die("Can't to open file!");print "<table>n";while ($csv_line=fgetcsv($salesFile)) {    # code...    print '<tr>';    for ($i=0,$j=count($csv_line);$i<$j; $i++) {         # code...        print '<td>'.htmlentities($csv_line[$i]).'</td>';    }    print "</tr>n";}print "</table>n";fclose($salesFile) or die("Can't to close file!"); ?>

php读取csv文件

本文由澳门太阳娱乐集团官网发布于脚本专栏,转载请注明出处:【太阳集团太阳娱乐登录】php将数组输出为.csv文

上一篇:【ASP.NET Web API教程】4.3 ASP.NET Web API中的异常处理 下一篇:没有了
猜你喜欢
热门排行
精彩图文