how to insert anchor tag in export csv report php? -
i want insert anchor tag ( url open csv report ) in csv export.
i have 2 variables header , data respectively $csv_header , $csv_lines.
in $csv_lines have urls , want export it.
my csv code
$csv_header = "\"developer name\",\"url\" \n"; $csv_lines =eregi_replace(" ", " ", "\"$developer_name\",\"$url\" \n");
for example $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 ;
there few points consider..
csv
plain text, , doesn't support type of format.you shouldn't try write own
csv
. usefputcsv()
if your'e still going continue workingcsv
format.you can use
xls builder
or equivalent whichever software you're looking open in.you can use
.xls
extension , output normal html table , spreadsheet software shall handle gracefully.
<?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 ; ?>
Comments
Post a Comment