一,首先要确认php版本,最好是高于5.6
二,将以下两行代码放入php.ini中并且重启
//这个是开启扩展
extension=php_com_dotnet.dll
//这个是COM扩展里自带的,只需将前面的;去掉就可以了
com.allow_dcom = true
三,自己编写一个三方类库文件,phpcom.php,如下:
<?php
class PHPcom {
/**
* 返回word内容,和字数(字符数),版本
* @param $url
* @return array
*/
public static function php_com($url)
{
$word = new COM("word.application") or die("Unable to instantiate Word");
//打开路径为URL的word,doc或docx都可以
$word->Documents->OPen($url);
//读取内容
$test= $word->ActiveDocument->content->Text;
//统计字数
$num = strlen($test);
//解决读取过程中乱码问题
$content= iconv('GB2312', 'UTF-8', $test);
//查看版本
$wor