有一种方法可以计算.doc中的单词数量吗?

时间:2014-04-24 12:46:06

标签: php string ms-word

我试图想办法用php计算.doc文档中的单词数。 我什么都没得到。

有人知道这样做的方法吗?我需要计算Word文档中的单词数。

由于

1 个答案:

答案 0 :(得分:1)

回答相同的问题:PHP - Get a word count from an uploaded Microsoft Word document

您需要:

区分文件类型

$file_name = $_FILES['image']['name'];
$file_extn = end(explode(".", strtolower($_FILES['image']['name'])));

if($file_extn == "doc" || $file_extn == "docx"){
    docx2text();
}elseif($file_extn == "rtf"){
    rtf2text();
}

将文档转换为文本

https://stackoverflow.com/a/7371315/2512934代表doc或docx http://webcheatsheet.com/php/reading_the_clean_text_from_rtf.php代表rtf

计算单词http://php.net/manual/en/function.str-word-count.php

我希望这有帮助吗?