将doc转换为txt

时间:2014-03-27 10:14:05

标签: php ms-word doc

我在Linux服务器上,我需要使用PHP将MS Word 97-2003 .doc格式转换为纯文本.txt文件

我已经尝试过这个解决方案:

How to extract text from word file .doc,docx,.xlsx,.pptx php

Extract text from doc and docx

但两者都适用于.docx格式。

问题是当我转换文件时,我在文本末尾有废字符。 我不需要的字符长度取决于文件的长度。 此外,如果文件有点长,可能会发生截断。

有没有简单的方法来转换?

2 个答案:

答案 0 :(得分:0)

我终于开始使用以下解决方案,启动了Antiword:

private function doc() {
    $file = escapeshellarg($this->filename);
    $text = `/usr/sbin/antiword -w 0 $file`;
    return html_entity_decode(utf8_encode(trim($text)));
}

答案 1 :(得分:-2)

我回答我自己的问题。 经过一番搜索后,我从iFile中找到了这个lib: http://www.isapp.it/ifile/it/APIDocument_v1.2/ifile/adapter-helpers/_adapter---helpers---class.doc2txt.php.html

它实际上对.doc和.rtf

都很有效
相关问题