0

I'm trying to figure a way to count the number of words in a .doc document with php. I get nothing at all.

Someone knows a way to do that? I need to count the number of words in a Word document.

Thanks

Igor Martins
  • 2,015
  • 7
  • 36
  • 57
  • 1
    possible duplicate of [PHP - Get number of pages in a Word document](http://stackoverflow.com/questions/1156761/php-get-number-of-pages-in-a-word-document) – Amal Murali Apr 24 '14 at 12:47
  • 1
    http://stackoverflow.com/questions/17967828/php-get-a-word-count-from-an-uploaded-microsoft-word-document – Matt Thomas Apr 24 '14 at 12:49

1 Answers1

1

Same question with a good answer: PHP - Get a word count from an uploaded Microsoft Word document

You will need to:

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();
}

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

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

I hope this helps?

Community
  • 1
  • 1
Peter Bennett
  • 184
  • 1
  • 2
  • 15