<?php
//allow com extension
ini_set("com.allow_dcom","true");

// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";
//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a Dinesh Kumar Shrivastava");
$word->Documents[1]->SaveAs("C:\Downloads\mydoc.docx");

//closing word
$word->Quit();

//free the object
$word = null;
?>

We can also create files(any format) using touch function in php.

<?php touch("test.docx"); ?>

Advertisements