我想在 csv 导出中插入锚标记(通过 csv 报告打开的 url)。
我有两个用于标头和数据变量,分别是 $CSV_header 和 $CSV_lines。
在$CSV_lines中,我有URL,我想导出它。
我的 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 ;
有几点需要考虑。
-
CSV
是纯文本,不支持这种类型的格式。 -
你不应该尝试写自己的
CSV
。如果您仍要继续使用CSV
格式,请使用fputcsv()
。 -
您可以使用
XLS Builder
或等效软件来打开它。 -
您可以使用
.xls
扩展并输出一个普通的HTML表格,电子表格软件将优雅地处理它。
<?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