【问题标题】:PHP - Get a word count from an uploaded Microsoft Word documentPHP - 从上传的 Microsoft Word 文档中获取字数
【发布时间】:2013-07-31 22:11:34
【问题描述】:

我正在尝试从上传的 word doc (.doc, .docx, .rtf) 中获取字数,但它总是带有令人讨厌的 Word 格式。

以前有人处理过这个问题并知道如何解决吗? 谢谢:)

【问题讨论】:

标签: php upload ms-word .doc


【解决方案1】:

您需要:

  1. 区分文件类型

    $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. 将文档转换为文本

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

  3. 数单词 http://php.net/manual/en/function.str-word-count.php

【讨论】:

  • 感谢您的回复 :) 这对 .docx 非常有效,但不幸的是不适用于 .rtf。你不觉得你也能帮我吗? :)
  • 我已经编辑了答案。如果我已经回答了您的问题,请将我的问题标记为问题的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
相关资源
最近更新 更多