Skip to content Skip to sidebar Skip to footer

PHP: HTML To DOCX

I am trying to figure out if there is a way to convert HTML to DOCX file using PHP. HTML comes from wysiwyg editor (with inline styles) and I want to be able to create a DOCX file

Solution 1:

You can approach it like this:

<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b>My first document</b>";
echo "</body>";
echo "</html>";
?>

You can add inline styles like so:

echo "<h1 style=\"color:red;\"> Hello World! </h1>";

Post a Comment for "PHP: HTML To DOCX"