如何使用php将html转换为word? [英] How to convert html to word using php?

查看:683
本文介绍了如何使用php将html转换为word?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP脚本将 HTML转换为MS WORD文档(.doc/.docx).使用Internet上可用的脚本,我能够将HTML文本转换为doc.但是我需要在文档中添加内联CSS的全部html.我制作了一个脚本

I am trying to convert HTML to MS WORD document (.doc/.docx) with PHP script. With the available scripts from internet I am able to convert the text of HTML to doc. But I need total html with inline css will be in my doc.I made one script

$html = file_get_contents('html path');
$tags = "<br>";
$test = strip_tags($page,$html);
$breaks = array("<br />","<br>","<br/>");  
$text = str_ireplace($breaks, "\r\n", $test);  
$text = iconv('UTF-8', 'ASCII//TRANSLIT',$text);
$handle = fopen("newdoc.doc", "w+");
fwrite($handle, $text);
fclose($handle);

它仅适用于HTML的文本内容. 但是我不能在其中添加图像吗?请帮忙,谢谢.

It's working for the text content of HTML only. But I can't add images to it is there any way to do it ? Please Help, Thanks in advance.

推荐答案

只需将以下代码保留在页面顶部即可进行转换:

just keep following code in top of the page need to convert:

<? header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=Report.doc");
?>

这篇关于如何使用php将html转换为word?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆