Page 1 of 1

Word count on a MS Doc file

Posted: Thu Jan 15, 2009 11:52 am
by radium35
is there a way to upload a .doc file and do a word count on it?

<?



$word = new COM("word.application") or die("Unable to instantiate Word");

$word->Visible = 1;


$word->Documents->Open("c:\anydoc.doc");
$temp = $word->Dialogs->Item(228); // returns wdDialogToolsWordCount dialog object
$temp->Execute(); //updates the word count
$numwords = $temp->Words(); //gets the words out of it

echo 'Word count = '.$numwords;

$word->Quit();

$wordss = $_POST[words];

$myFile = "test.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 1000000);
fclose($fh);

//echo "$theData";

?>

<?
$content = "$theData";
$str_array = split(" ",$content);
$word_count = 0;


for($i=0;$i<sizeof($str_array);$i++)
{
if(strlen($str_array[$i]) > 1)
{
$word_count++;
}
}

echo $word_count;
?>