php将html转成word文档下载
Posted CoKeny
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php将html转成word文档下载相关的知识,希望对你有一定的参考价值。
<meta charset="utf-8" /> <?php 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(); } function wirtefile($fn,$data){ $fp=fopen($fp,$data); fwrite($fp,$data); } } $html=‘ 这里是html的内容 <form action="ceshi.php" method="post"> <button name="aa" value="cc">转换成word文档</button> </form> ‘; //批量生成 //for($i=1;$i<3;$i++){ $word = new word(); $word->start(); $wordname=‘word.doc‘; echo $html; $aa = "cc"; if($aa[email protected]$_POST[‘aa‘]){ //echo @$aa; //$word->save($wordname); @header(‘Content-type:application/word‘); header(‘Content-Disposition: attachment; filename=‘.$wordname.‘‘); @readfile($wordname); ob_flush();//每次执行前刷新缓存 flush(); //} }else{ echo ""; } ?>
以上是关于php将html转成word文档下载的主要内容,如果未能解决你的问题,请参考以下文章