PHP导出word(纯文字)

<?php
echo '
<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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<xml><w:WordDocument><w:View>Print</w:View></xml>
<script src="includes/js/ztree/js/jquery-1.4.4.min.js" type="text/javascript"></script>
</head>
<body>
//这里是你想输出的内容,按HTML的格式就可以了。
</body>
</html>
';

ob_start(); //打开缓冲区
header("Cache-Control: public");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");

if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE'))
{
header('Content-Disposition: attachment; filename='.$row->name.$row->date.'.doc');
}
else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox'))
{
Header('Content-Disposition: attachment; filename='.$row->name.$row->date.'.doc');
}
else
{
header('Content-Disposition: attachment; filename='.$row->name.$row->date.'.doc');
}
header("Pragma:no-cache");
header("Expires:0");
ob_end_flush();
?>

这是网上找的代码,改一改终于可以用,虽然也不清楚具体是什么原理,但是能解决问题就行了先。有空再理解一下代码的含义吧~(虽然这么说基本就不会看了)待续……


你可能感兴趣的:(PHP,word,导出文档)