方案一 $html2 ='数字'; header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); header("Accept-Length: ".strlen($html2)); header('Content-Disposition: attachment; filename=test.doc'); header("Pragma:no-cache"); header("Expires:0"); echo $html2;
//此方法是放入缓冲区输出, 默认4096. 超出自动就输出到浏览器上了。 可以修改配置文件 output_buffering = 4096 改成 On (无限大) $html2 = '实验中学'; echo $html2; ob_start(); header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); header("Accept-Length: ".strlen($html2)); header('Content-Disposition: attachment; filename=test.doc'); header("Pragma:no-cache"); header("Expires:0"); ob_end_clean();