Introduction
In this article I explain how to create a Word document file by PHP. A document file is created using HTTP headers. This is very simple and useful in PHP when the user opens a PHP application in a Word document then you can use that and easily create a document file using PHP but this file is not a pure document file but certainly it can be opened in a document application.
Example
<?php
//header part
header("Content-type: application/vinod.ms-word");
header("Content-Disposition: attachment;Filename=MCN.doc");
//starting html tag
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
//body part start here
echo "<body>";
//print the content
echo "<b>This is my first document created by PHP</b>";
echo "</body>";
//end html tag
echo "</html>";
?>
Output
For opening and saving a document:

This document file you can only read, not write, the file.

In the next example I will explain a document file with a COM object. Here COM only works in Windows and COM functions are only available for the Windows version of PHP. First a Word document is saved then is sent the browser to be read. In this example I will use the "sys_get_temp_dir()" function; this function returns a directory path used for a temp directory.
Example 1
<?php
$doc = new Com("word.application");
$doc->Visible =0;

mainak paruiPosted Sep 12, 2018, 7:42 AM
You are a genious sir..