Posted By

jonhenshaw on 09/12/08


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Convert Word Document to TXT (text) File

 / Published in: PHP


Use this PHP script to read and convert a Word document to a text file

  1. $filename="file.doc";
  2. $TXTfilename = $filename . ".txt";
  3. $word = new COM("word.application") or die("Unable to instantiate Word object");
  4. $word->Documents->Open($filename);
  5. // the '2' parameter specifies saving in txt format
  6. $word->Documents[1]->SaveAs($TXTfilename ,2);
  7. $word->Documents[1]->Close(false);
  8. $word->Quit();
  9. $word->Release();
  10. $word = NULL;
  11. unset($word);
  12. $content = file_get_contents($TXTfilename);
  13. unlink($TXTfilename);

Report this snippet  


RSS Icon Subscribe to comments
Posted By: ninjapug on April 5, 2010

How do i save as a unicode txt file. I am working in a project where i need to convert chinese words docs into txt

You need to login to post a comment.