Sometimes we may need to know the total characters in a word document. We can do this by creating a COM object..
Sample code:
$word = new COM("word.application") or die("Unable to instanciate Word"); $word->Visible = 0; $word->Documents->Open("D:\test\xyz.doc"); // give the path to your word document $total_characters_in doc = $word->ActiveDocument->Characters->Count; $total_paragraph = $word->ActiveDocument->Paragraphs->Count;
So now from the above example,
$total_characters_in doc will give you the total number of characters including the carriage returns
$total_paragraph will give you the total number of paragraphs in the word document.
If you need to count only the characters and NOT the carriage returns, then you can do this as follows :
$only_characters = $total_characters_in doc - $total_paragraph ;
Reference:
http://msdn.microsoft.com/en-us/library/4zbbd3wt.aspx