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 = ' <table width=600 cellpadding="6" cellspacing="1" bgcolor="#000"> <tr bgcolor="White"> <td>dmy</td> <td><a href="" target="_blank" >dmy</a></td> </tr> <tr bgcolor="red"> <td>dai</td> <td><a href="" target="_blank" >dai</a></td> </tr> <tr bgcolor="White"> <td colspan=2 > dd<br> </td> </tr> </table> '; //批量生成 for($i=1;$i<=1;$i++){ $word = new word(); $word->start(); //$html = "aaa".$i; $wordname = $_SERVER['DOCUMENT_ROOT'].'/chinaBank/word/dd.doc'; echo $html; $word->save($wordname); ob_flush();//每次执行前刷新缓存 flush(); }