-1

I am new to PHP. I have written a script for converting HTML to DOC. It is working fine while opening this file in editor rather than Microsoft Doc.

While opening this file in Microsoft word it is not recognizing some special characters including "<" and ">" symbols.

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..

2 Answers2

0

You're asking Microsoft Word to open this as an HTML file but you're not using proper HTML. < should be &lt; and > should be &gt;

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>.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
0

If what you are doing is rendering html code into file and set its extension to doc, then Microsoft Doc opens it as html file and so you need convert reserved HTML characters to character entities.: < to < and so on: http://www.w3schools.com/html/html_entities.asp

Meeps
  • 41
  • 3