<?php
if($_POST['str'])
{
header('Content-type: application/doc');
header('Content-Disposition: attachment; filename="downloaded.doc"');
echo iconv("UTF-8","GB2312",$_POST['str']);
}
?>
<a href="javascript:void(0)" onclick="downword()">下载</a>
<div id="word" style="display:none">加息预期下银行再推固息房贷
</div>
<form action="" method="POST" name="form">
<textarea style="display:none" name="str" id="down"/></textarea>
</form>
<script>
function downword()
{
var doc=document.getElementById("word").innerHTML;
document.getElementById("down").value=doc;
document.form.submit();
}
</script>
如果想生成其它的文件,将doc改成其它的扩展名就OK了