PHP - Get a word count from an uploaded Microsoft Word document

最后都变了- 提交于 2019-12-05 06:40:32

问题


I am trying to grab a word count from an uploaded word doc (.doc, .docx, .rtf) but it always carries through the annoying Word formatting.

Anybody tackled this issue before and know how to solve it? Thanks :)


回答1:


You will need to:

  1. Distinguish the file type

    $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();
    }
    
  2. Convert the document to text

    https://stackoverflow.com/a/7371315/2512934 for doc or docx http://webcheatsheet.com/php/reading_the_clean_text_from_rtf.php for rtf

  3. Count the words http://php.net/manual/en/function.str-word-count.php



来源:https://stackoverflow.com/questions/17967828/php-get-a-word-count-from-an-uploaded-microsoft-word-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!