php导出csv

    //导出订单
    private function _export_collection($data_v)
    {
        $data = array();
        $up_status = $this->up_status();
        $progress_status = $this->progress_status();
        $mobile_status = $this->mobile_status();
        $cy_status=$this->cy_status();
        $data[] = array('手机号码', 'uid', '提交时间', '联系人', '公司名称', '机构类型', '当前职位', '所在地区', '工作年限', '擅长领域', '是否创业', '创业方向', '是否有课', '课程名称', '备注', '操作记录', '状态', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', '来源', '电话有效性', '进展', '跟进备注', '分配对象');
        foreach ($data_v as $key => $mobile) {
            $i = 1;
			$data[] = array(
				"\t" . $v['mobile'],
				$v['uid'],
				date('Y-m-d H:i:s', $v['dateline']),
				$v['contact'],
				$v['company'],
				$v['organize'],
				$v['job'],
				$v['area'],
				$v['work_year'],
				$v['skill'],
				$v['cy'] >= 1 ? $cy_status[$v['cy']] : '',
				$v['cy_direction'],
				$v['video'] >= 1 ? $cy_status[$v['video']] : '',
				$v['video_name'],
				$v['remark'],
				$mobile['collection_log'][0]['dateline'] ? sprintf('%s %s %s',date('Y-m-d H:i:s', $mobile['collection_log'][0]['dateline']) , $mobile['collection_log'][0]['username'], str_replace(array(','),'|',$mobile['collection_log'][0]['remark'])) : '',
				$up_status[$v['status']],
				$v['utm_source'],
				$v['utm_medium'],
				$v['utm_campaign'],
				$v['utm_content'],
				$v['utm_term'],
				$v['source'],
				$v['mobile_status'] > 1 ? $mobile_status[$v['mobile_status']] : '',
				$v['progress'] == 0 ? '' : $progress_status[$v['progress']]['name'],
				$v['username_remark'],
				$v['ownership'],
			);
			$i = $i + 1;
        }
        fx_phpexcel_utl::export_csv($data);
    }


    // CVS导出速度快
    public static function export_csv($data)
    {
        $string = "";
        foreach ($data as $key => $value) {
            foreach ($value as $k => $val) {
                $value[$k]= str_replace(array(","), '|',  $value[$k]);
                $value[$k] = iconv('utf-8', 'gbk//IGNORE',  str_replace(array("\n", "\r"), '',  $value[$k]));
            }
            $string .= implode(",", str_replace(PHP_EOL, '',  $value)) . "\n"; //用英文逗号分开
        }
        $filename = date('Ymd') . '.csv'; //设置文件名
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename=" . $filename);
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        echo $string;
    }