1. Open COM option in php.ini First, com.allow_dcom = True
2. My environment here is php5.4.7,php 5.4.5, com/dotnet module has become a separate extension, so need to configure Extension=php_com_dotnet.dll in php.ini, if PHP version< 5.4.5 is not needed. Otherwise, it may be an error Fatal Error:class ' COM ' not found.
The configuration method is: Simply add Extension=php_com_dotnet.dll to the extended list
3. It is also necessary to understand that, although the COM component is also a DLL extension, it is not a php extension, so it is wrong to copy the Senc.dll to the Php/ext directory and then add it to the php.ini, which PHP does not recognize.
Establish an index to the new COM component
$word = new COM ("Word.Application") or Die ("Can ' t start word!");
Displays the version number of Word that is currently in use
echo "Loading Word, v. {$word->version}";
Set its visibility to 0 (false), if you want it to open at the front end, use 1 (true)
To open the application in the forefront, use 1 (true)
$word->visible = 0;
Call a document.
$word->documents->open (DirName (__file__). /1.doc ");
Reading the contents of a document
$test = $word->activedocument->content->text;
Echo $test;
echo "";
Change the variables in the document that need to be changed
$test =str_replace ("<{variable}>", "This is variable", $test);
Echo $test;
$word->documents->add ();
Add text to a new document
$word->selection->typetext ("$test");
Save the document in the directory
$word->documents[1]->saveas ("2.doc");
Turn off connection to COM components
$word->quit ();