我是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;
提前致谢..
答案 0 :(得分:0)
您要求Microsoft Word将其作为HTML文件打开,但您没有使用正确的HTML。 <
应为<
,>
应为>
https://dev.w3.org/html5/html-author/charref
PHP可以使用htmlentities()转换所有这些字符,但您不希望在整个字符串上执行此操作,因为您有<p>
和</p>
等HTML标记。
答案 1 :(得分:0)
如果你正在做的是将html代码渲染到文件中并将其扩展名设置为doc,那么Microsoft Doc将其打开为html文件,因此您需要将保留的HTML字符转换为字符实体: &LT;到&lt; 等等: http://www.w3schools.com/html/html_entities.asp