【问题标题】:PHP Export DOC file is not coming correctly in Microsoft WordPHP 导出 DOC 文件在 Microsoft Word 中不正确
【发布时间】:2016-05-30 15:27:06
【问题描述】:

我是 PHP 新手。我编写了一个将 HTML 转换为 DOC 的脚本。在编辑器而不是 Microsoft Doc 中打开此文件时工作正常。

在 Microsoft Word 中打开此文件时,它无法识别某些特殊字符,包括“”符号。

请在下面找到我的代码并帮助我解决此问题

$ExportContent = '<p>Suppression of NF-κB activity by SAC-Par-4 in PC3-NF-κB-luc and MAT-LyLu-NF-κB-luc cells was studied as described earlier. NF-κB luciferase activity was significantly increased in PC3 cells by ∼2.0-fold and in MAT-LyLu cells by ∼4.0-fold in TNF-α-stimulated cells compared with the untreated control group. However, the TNF-α-stimulated luciferase activity was significantly reduced (p < 0.05) to approximately 2 fold by 30 μg/ml of SAC-Par-4 treatment in both cell lines. In parallel, there was no suppression of NF-κB activity observed in case of TNF-α-stimulated HEK293- NF-κB-luc cells upon treatment with 30 μg/ml of SAC-Par-4-GFP (Figure 3B).</p>';

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=testdocument.docx");

echo $ExportContent;

提前谢谢..

【问题讨论】:

    标签: php html doc


    【解决方案1】:

    您要求 Microsoft Word 将其作为 HTML 文件打开,但您没有使用正确的 HTML。 &amp;lt; 应该是 &amp;lt;&amp;gt; 应该是 &amp;gt;

    https://dev.w3.org/html5/html-author/charref

    PHP 可以使用 htmlentities() 转换所有这些字符,但您不想对整个字符串执行此操作,因为您有诸如 &lt;p&gt;&lt;/p&gt; 之类的 HTML 标记。

    【讨论】:

      【解决方案2】:

      如果您正在将 html 代码呈现为文件并将其扩展名设置为 doc,则 Microsoft Doc 将其作为 html 文件打开,因此您需要将保留的 HTML 字符转换为字符实体。: http://www.w3schools.com/html/html_entities.asp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-31
        • 2015-03-26
        • 1970-01-01
        • 1970-01-01
        • 2014-05-04
        • 1970-01-01
        相关资源
        最近更新 更多