I want to count number of words from .doc and .docx file.
I have tried below code:-
$file_upload = 'test.docx';
$zip = new ZipArchive;
$file_content = " ";
if ($zip -> open($file_upload) === true)
{
if ( ($index = $zip -> locateName("word/document.xml")) !== false )
{
$data = $zip -> getFromIndex($index);
$xml->formatOutput = true;
$xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
$file_content = strip_tags($xml -> saveXML());
}
echo str_word_count($file_content);
}
But the above code is not giving me the expected result.
I also searched google and also stackoverflow search section. But I didn't found my desired answer.
NOTE:- The code will not be operating system or server dependent.