亲自测试效果一般, css的样式文件获取不到
如果没有特殊的样式 或者是内容里面包括样式的 直接输出有样式的内容 然后导出 这样还是可以的
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= file_get_contents('https://www.163.com'); $word = new word(); $word->start(); //$html = "aaa".$i; $wordname = "2.doc"; echo $html; $word->save($wordname); ob_flush();//每次执行前刷新缓存 flush();