WORD:
<?php header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); //有了這些,可以把帶html標簽的html源碼導入到word里,並且可以保持html的樣式。 /* <STYLE> BR.page { page-break-after: always } </STYLE> 在<head>部分加這個是為了實現打印的時候分頁 */ $wordStr = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <STYLE> BR.page { page-break-after: always } </STYLE> </head><body>'; $wordStr = "<b>hello</b><p>this is html code</p>"; $wordStr .= '</body></html>'; //防止導出亂碼 $file = iconv("utf-8", "GBK", $filename); header("Content-Type: application/doc"); header("Content-Disposition: attachment; filename=" . $file . ".doc"); echo $wordStr; ?>
CVS:
<?php header("Content-Disposition: attachment; filename=郵寄地址.csv"); echo "姓名,性別,年齡,電話\n張三,男,23,15010125818"; ?>
注:echo中的逗號是每個列的分割標識符,\n則是換行。
還有如下可參考:
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
PDF:
<?php header("Content-type:application/pdf"); // 文件將被稱為 downloaded.pdf header("Content-Disposition:attachment;filename='downloaded.pdf'"); // PDF 源在 original.pdf 中 readfile("original.pdf"); ?> <html> <body> ... ...