简体   繁体   English

PHP 导出 DOC 文件在 Microsoft Word 中不正确

[英]PHP Export DOC file is not coming correctly in Microsoft Word

I am new to PHP.我是 PHP 新手。 I have written a script for converting HTML to DOC.我已经编写了一个将 HTML 转换为 DOC 的脚本。 It is working fine while opening this file in editor rather than Microsoft Doc.在编辑器而不是 Microsoft Doc 中打开此文件时它工作正常。

While opening this file in Microsoft word it is not recognizing some special characters including "<" and ">" symbols.在 Microsoft Word 中打开此文件时,它无法识别某些特殊字符,包括“<”和“>”符号。

Please find my code below and help me out what to do for this issue请在下面找到我的代码并帮助我解决此问题

$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;

Thanks in advance..提前致谢..

You're asking Microsoft Word to open this as an HTML file but you're not using proper HTML.您要求 Microsoft Word 将其作为 HTML 文件打开,但您没有使用正确的 HTML。 < should be &lt; <应该是&lt; and > should be &gt;并且>应该是&gt;

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

PHP can convert all of these characters using htmlentities() but you don't want to do this on your entire string since you have HTML tags like <p> and </p> . PHP 可以使用 htmlentities() 转换所有这些字符,但您不想对整个字符串执行此操作,因为您有像<p></p>这样的 HTML 标签。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM