How to get content of MS word document

Discussion in 'PHP' started by johristov, Nov 11, 2011.

  1. #1
    Hi, I am developing a site for free education materials for colege students. I want to make a preview of the content of the file on the download page, but no success. I found many threads for reading .txt with php but .doc seems to be impossible to me. I have tried this one:
    <?php$word = new COM("word.application") or die("Unable to instantiate Word");$word->Documents->Open("referats/068d82f3.doc");$newfilename = substr($filename,0,-4) . “.txt”;
    // the '2' parameter specifies saving in txt format$word->Documents[1]->SaveAs("referats/068d82f3.txt");$word->Documents[1]->Close(false);$word->Quit(); $word->Release();$word = NULL;unset($word);
    $fh = fopen($newfilename, ‘r’); $contents = fread($fh, filesize($newfilename));fclose($fh);unlink($new_filename);
    echo $contents;
    ?>
    PHP:
    , but still nothing! With file_get_content I got only some weird simbpls...If somepne can halp me I will be very grateful...
     
    johristov, Nov 11, 2011 IP