如题。
以前也有csv出力 但是第一行就是标题行,但是这次的第一行就是空行,诗句从第二行开始的。

解决方案 »

  1.   

        function getCSV($fileName,$title,$data){
            $this->setTitle($title);
            $this->setData($data);
            header("Content-Type: text/csv");
            header("Content-Disposition: attachment; filename={$fileName}.csv");
            echo mb_convert_encoding($this->csv_data,'Shift_JIS','EUC-JP');
            exit;
        }    function setTitle($title){
            $this->keys = array_keys($title);
            if (is_array($title) && $title != "") {
                foreach ($title as $key => $val) {
                    $title[$key] = str_replace(',' , ",", $val);
                }
                $this->csv_data .= implode(",", $title)."\n";
            }
        }    function setData($data){
            if (is_array($data) && $data != "") {
                foreach ($data as $d_val) {
                    $line = "";
                    foreach ($this->keys as $key) {
                        $line .= '"'.$d_val[$key].'"'.",";
                    }
                    $line = substr($line,0,-1);
                    $this->csv_data .= $line."\n";            }
            }
        }
    用的基类文件。
    $fileName 文件名,$title 标题,$data 数据