- Convert HTML to MS Word Document using PHP
- HTML To Word (DOC/DOCX) Library
- Convert HTML to Word Document
- Hello World!
- Create Word Document from HTML File
- Word Document File Format
- Conclusion
- Онлайн-конвертер PHP to Word
- Как Конвертировать PHP to Word
- часто задаваемые вопросы
- Еще приложений
- Онлайн-конвертер PHP to DOCX
- Как Конвертировать PHP to DOCX
- часто задаваемые вопросы
- Еще приложений
Convert HTML to MS Word Document using PHP
The conversion of HTML into MS Word Document mainly used in the web application to generate a .doc/.docx file with dynamic HTML content. Microsoft word document is the most popular file format to export dynamic content for offline use. Export HTML content to MS word functionality can be easily implemented using JavaScript. But, if you want to convert dynamic content to Doc, server-side interaction is needed.
The server-side export to word functionality is very useful to convert dynamic HTML content to MS word document and download as a .docx file. The MS word document can be easily generated with HTML content using PHP. In this tutorial, we will show you how to convert HTML to MS word document in PHP.
HTML To Word (DOC/DOCX) Library
The HTML_TO_DOC class is a custom library that helps to generate MS word documents and include the HTML formatted content in the Word document using PHP.
- setDocFileName() – Set document file name.
- setTitle() – Set document title.
- getHeader() – Create header section of the document.
- getFotter() – Create footer section of the document.
- createDoc() – Create word document in .dcox format.
- _parseHtml() – Parse and filter HTML from source.
- write_file() – Insert content in the word file.
/**
* Convert HTML to MS Word document
* @name HTML_TO_DOC
* @version 2.0
* @author CodexWorld
* @link https://www.codexworld.com
*/
class HTML_TO_DOC
<
var $docFile = '';
var $title = '';
var $htmlHead = '';
var $htmlBody = '';
/**
* Constructor
*
* @return void
*/
function __construct() <
$this->title = '';
$this->htmlHead = '';
$this->htmlBody = '';
>
/**
* Set the document file name
*
* @param String $docfile
*/
function setDocFileName($docfile) <
$this->docFile = $docfile;
if(!preg_match("/\.doc$/i",$this->docFile) && !preg_match("/\.docx$/i",$this->docFile)) <
$this->docFile .= '.doc';
>
return;
>
/**
* Set the document title
*
* @param String $title
*/
function setTitle($title) <
$this->title = $title;
>
/**
* Return header of MS Doc
*
* @return String
*/
function getHeader() <
$return = xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
Читайте также: Http hrportal sibintek ru view doc html