首頁  >  文章  >  後端開發  >  permeo security driver php csv操作類別程式碼

permeo security driver php csv操作類別程式碼

WBOY
WBOY原創
2016-07-29 08:41:251083瀏覽

請點選後面位址下載:csv操作類別
使用說明如下:
1.產生csv檔案

複製程式碼程式碼如下:


require "./include/csvdatafile.php";
set_time_limit(200);
header("Content-type: application/RFC822");
header('Content-Disposit. : attachment; filename=export.csv');
$arr_export_titles = array("學生編號","學號","學生姓名");
$csvfile = new csvDataFile("", "," , "w");
echo $csvfile->printline($arr_export_titles);
//方法一
$print_data1[] = 1;
$print_data1[] = "039413301"; 🎜>$print_data1[] = "張三";
echo $csvfile->printline($print_data1);
$print_data2[] = 2;
$print_data2[] = "039413302";
$print_data2[] = "039413302"; >$print_data2[] = "李四";
echo $csvfile->printline($print_data2);
$print_data3[] = 3;
$print_data3[] = "039413303";
;
; $print_data3[] = "王五";
echo $csvfile->printline($print_data3);
//方法二
$print_data[1][] = 1;
$print_data[ 1][] = "039413301";
$print_data[1][] = "張三";
$print_data[2][] = 2;
$print_data[2][] = " 039413302";
$print_data[2][] = "李四";
$print_data[3][] = 3;
$print_data[3][] = "039413303";
$print_data[3][] = "039413303";
$print_data[3][] = "王五";
echo $csvfile->printcsv($print_data);



2.開啟csv讀取資料
程式碼

複製程式碼

程式碼如下:



require "./include/csvdatafile.php";
$filename = "E:/development = "E:/development /csvfile/datefile.csv";
// Read file source
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
// format content for special chars
$contents = @addslashes($contents);
$contents = @str_replace(',', ' ,', $ contents);
$contents = @stripslashes($contents);
// Write to new file
$handle = @fopen($filename, "w");
@fwrite($handle , $contents);
@fclose($handle);
$fd = @fopen($filename, "rb");
$first_line = str_replace(' ,',',',str_replace( '"','',trim(@fgets($fd, 1000)))) ;
@fclose($fd);
if($first_line != "學生編號,學號,學生姓名" ) {
$pass = false;
}
if($pass){
$csv = new csvDataFile($filename);
while($csv->next_Row()) {
$userid = trim($csv->f('學生編號'));
$classno = trim($csv->f('學號'));
$username = trim( $csv->f('學生姓名'));
}
}

以上就介紹了permeo security driver php csv操作類別程式碼,包含了permeo security driver方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn