本文實(shí)例講述了php從csv文件讀取數(shù)據(jù)并輸出到網(wǎng)頁的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?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程序設(shè)計有所幫助。