Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1425
  • Last Modified:

doc2txt php script

Hi,
could you provide me a php script that convert a doc document loaded in a variable ($document) to txt?
I don't need to maintain the format.

thanks
0
nokiamobile
Asked:
nokiamobile
1 Solution
 
cammjCommented:
It's not possible to directly read doc files if they were created using Microsoft Word, because the files are stored in a binary format that PHP cannot understand.

It is possible to leverage Microsoft Word to do the reading of the files though, but this requires that the OS you are running your php scripts on is a Windows machine and also has access to a copy of Microsoft Word.

This can be done with something like this

$filehandler = new COM("word.application");
$filehandler->Documents->Open(realpath("pathtomydocument.doc"));
$file = (string) $filehandler->ActiveDocument->Content;

echo $file;

$filehandler->ActiveDocument->Close(false);
$filehandler->Quit();
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now