如何在导出csv报告php中插入锚标记?

时间:2016-01-28 09:47:29

标签: php csv

我想在csv export中插入锚标记(由csv报告打开的网址)。

我有两个标题和数据变量,分别是$ CSV_header和$ CSV_lines。

在$ CSV_lines中我有网址,我想导出它。

我的CSV代码

$CSV_header =
"\"DEVELOPER NAME\",\"Url\" \n";

$CSV_lines =eregi_replace(" ", " ", "\"$developer_name\",\"$url\" \n");

例如$ url = <a href="http://www.example.com">Example</a>

$FILE_TIME = date("Y-m-d H:i:s");
$CSVfilename = "REPORT_$US$FILE_TIME.csv";
        header('Content-type: application/octet-stream');
        header("Content-Disposition: attachment; filename=\"$CSVfilename\"");
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        ob_clean();
        flush();
        echo $CSV_header;
        echo $CSV_lines ;

1 个答案:

答案 0 :(得分:0)

有几点需要考虑..

  1. CSV是纯文本,不支持此类格式。

  2. 您不应该尝试编写自己的CSV。如果您仍然继续使用fputcsv()格式,请使用CSV

  3. 您可以使用XLS Builder或某些等效内容来查找要打开的软件。

  4. 您可以使用.xls扩展程序并输出普通的HTML表格,电子表格软件可以优雅地处理它。

  5. <?php
    $CSV_lines 
        = "<table border=1>
            <tr>
              <td>1</td>
              <td>DEVELOPER NAME</td>
              <td><a href='http://www.example.com'>Example</a></td>
            </tr>
          </table>";
    $FILE_TIME = date("Y-m-d H:i:s");
    $CSVfilename = "REPORT_$US$FILE_TIME.xls";
            header('Content-type: application/octet-stream');
            header("Content-Disposition: attachment; filename=\"$CSVfilename\"");
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            ob_clean();
            flush();
            echo $CSV_lines ;
    ?>
    

    <强> PHPFiddle