Friday, January 31, 2014

PHP - Export Content to MS Word document

The following PHP code to export content in MS Word document.
 $doc_body ="
 <h1>PHP - Export Content to MS Word document</h1>
 <p>This is a test.<p>
 <p>This is a test.<p>
 <form name="proposal_form" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post"">
  <input type="submit" name="submit_docs" value="Export as MS Word" class="input-button" />
          header("Content-Type: application/vnd.msword");
          header("Expires: 0");//no-cache
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");//no-cache
          header("content-disposition: attachment;filename=sampleword.doc");
          echo "<html>";
          echo "$doc_body";
          echo "</html>";      

video:Export Content to MS Word document


  1. Thanks for this code which is going to save my life. Please, how do you create a page break

  2. thanks for the code, but i gonna to how some sql query in the doc_body, how is the syntax to write php code inside the doc_body?

  3. when i click export button word doc generated and this should be attached to email. is it possible ?


  4. A great content and very much useful to the visitors. Looking for more updates in future.

    Selenium Training in Chennai