极乐门资源网 Design By www.ioogu.com
请点击后面地址下载:csv操作类
使用说明如下:
1.生成csv文件
复制代码 代码如下:
require "./include/csvdatafile.php";
set_time_limit(200);
header("Content-type: application/RFC822");
header('Content-Disposition: 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[] = "李四";
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][] = "王五";
echo $csvfile->printcsv($print_data);
2.打开csv读数据
代码
复制代码 代码如下:
require "./include/csvdatafile.php";
$filename = "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('学生姓名'));
}
}
使用说明如下:
1.生成csv文件
复制代码 代码如下:
require "./include/csvdatafile.php";
set_time_limit(200);
header("Content-type: application/RFC822");
header('Content-Disposition: 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[] = "李四";
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][] = "王五";
echo $csvfile->printcsv($print_data);
2.打开csv读数据
代码
复制代码 代码如下:
require "./include/csvdatafile.php";
$filename = "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('学生姓名'));
}
}
标签:
php,csv
极乐门资源网 Design By www.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无php csv操作类代码的评论...
更新日志
2024年11月13日
2024年11月13日
- 费玉清《天之大》SONY台湾版 [WAV+CUE][1G]
- 英雄联盟双城之战第二季主题曲谁唱的 双城之战2主题曲演唱歌手介绍
- 逆水寒2024双11活动有什么 2024双11特惠活动开始时间
- 宝可梦大集结国服和国际服有什么区别 大集结国服vs国际服
- YelenaEckemoff-RomanceoftheMoon(2024)[24-WAV]
- 群星《发烧醉乐坊太湖美(民乐典范)》[WAV+CUE]
- 中国发烧名盘《中国管弦-九州之韵》DTS[WAV]
- V社官宣推出白色限量版Steam Deck!11月18日上市
- 梦回2016!《守望先锋2》限时推出6v6怀旧模式
- 吴京谈《镖人》拍摄过程:演员们打得很爽 文戏也过瘾
- 林家谦.2024-ISFP【FLAC分轨】
- 群星.1996-摇滚柔情【正大国际】【WAV+CUE】
- 王菲.2000-寓言【EMI百代】【WAV+CUE】
- 群星《妙音纪念珍藏版贰》头版限量编号24K金碟 [低速原抓WAV+CUE][1G]
- 谭咏麟-《20世纪中华歌坛名人百集珍藏版》中唱[APE+CUE][1G]