验证中...
助力高校计算机教育 —— 码云为老师推出免费高校版,高达 200 人的协作团队
语言: PHP
分类: Web开发技术
最后更新于 2018-06-14 14:58
csv操作类
原始数据 复制代码
class Csv
{
public static function getDataFromFile($filePath, $uniqueField='id') {
static $data = array();
if(isset($data[$filePath])) {
return $data[$filePath];
}
$ret = array();
$f = fopen($filePath, 'r');
$head = fgetcsv($f);
while($row = fgetcsv($f)) {
$info = array_combine($head, $row);
$id = $info[$uniqueField];
$ret[$id] = $info;
}
$data[$filePath] = $ret;
return $data[$filePath];
}
public static function create($fileName, $contents, $code = 'utf-8'){
if($code != 'utf-8'){
$fileName = iconv('utf-8', $code, $fileName);
$contents = iconv('utf-8', $code, $contents);
}
header("Content-Type: text/csv");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Expires:0");
header("Pragma:public");
header("Content-Disposition: attachment; filename=" . $fileName . ".csv");
echo $contents;
exit;
}
}

评论列表( 0 )

你可以在登录后,发表评论

10_float_left_people 10_float_left_close