Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Counting number of words like Microsoft count

Erick MongiErick Mongi Member Posts: 1
in PHP

Hi there, I need to count number of words in ms word 2007 format using php, the problem is that the counting needs to be the same as it works in Microsoft Word, because I try to writing code but not 100% count words like ms word count. My script: //library from: https://www.phpclasses.org/package/8908-PHP-Convert-DOCX-DOC-PDF-to-plain-text.html require_once("includes/library_count_words.php");

$fileDir = $_FILES["docfile"]["name"];

$docObj = new Doc2Txt($fileDir);

$text = $docObj->convertToText();

$text = preg_replace('![^ \pL\pN\s]+!u', '', strtolower($text));
$text = trim( preg_replace('![ \s]+!u', ' ', $text) );

$count = count( explode(' ', $text) );

print "

Number of words : ".$count."

";

}

Any suggestion guys. Thanks

Tagged:
Sign In or Register to comment.