PHP保存网页为DOC 该怎么做。就是在我的网站内容页, 增加一个功能。点击后 自动把网页保存为DOC文档,并且可以下载!最好可以实现URL传递的功能比如点击: doc.PHP?url=xxx.com/xx.html 就把xxx.com/xx.html的页面保存为DOC了 求大神帮忙!
参考资料http://blog.csdn.net/wypblog/article/details/7768089http://www.jb51.net/article/46561.htmhttp://www.jbxue.com/article/6348.htmlhttp://www.lao8.org/article_1314/php_doc#shuohttp://my.oschina.net/kk2009/blog/174759
$url = 'http://www.baidu.com';
$content = file_get_contents($url);header('content-type:application/octet-stream');
header('content-disposition:attachment; filename=abc.doc');
header('content-length:'.strlen($content));
echo $content;
http://ldb360.com/doc.php<?php
$url = 'http://ldb360.com/';
$content = file_get_contents($url);
header('content-type:application/octet-stream');
header('content-disposition:attachment; filename=abc.doc');
header('content-length:'.strlen($content));
echo $content;
}
class word
{
function start()
{
ob_start();
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">';
}
function save($path)
{
echo "</html>";
$data = ob_get_contents();
ob_end_clean();
$this->wirtefile ($path,$data);
}
function wirtefile ($fn,$data)
{
$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}
}$html = '
\\输出内容<br />
<h1>文档标题</h1><br />
图文内容<br />
页脚-时间<br />
';
//批量生成
for($i=1;$i<=1;$i++){
$word =new word();
$word->start();
//$html = "aaa".$i;
$wordname ='doc/标题变量'.$i.".doc";
echo $html;
$word->save($wordname);
ob_flush();//每次执行前刷新缓存
flush();
}
这种做法的缺点是不能包装图片,也就是离开网站支持后,图片都无法显示
所以你至少得打包成 mht 格式文档才可以网上有一个 MhtFileMaker.php 你可拿来用用你#3的代码中并没有获取网页的内容,自然也就.....