Domanda

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.

È stato utile?

Soluzione

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Take a look to PHPDocX.

(source here)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top