方法一:使用com组件来完成
先开启php.ini的COM,配置文件里面有,直接去掉前面的注释即可
extension=php_com_dotnet.dll
com.allow_dcom = true
具体代码:
echo "开始转换:\n";
$open_file = 'D://Paper/aaa.doc';
$word = new COM("word.application") or die("Can't start Word!");
$word->Documents->open($open_file);
$test = $word->ActiveDocument->content->Text;
$content= iconv('GBK', 'UTF-8', $test);
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
var_dump($content);
echo "转换完成\n\t";
方法二:使用antiword组件来完成
需要先下载antiword,地址: http://www.winfield.demon.nl/
然后需要配置一下环境变量,配置方法:https://jingyan.baidu.com/article/0964eca24fa7938285f536a6.html
echo "开始转换:\n\t";
$content = shell_exec('antiword.exe -m UTF-8 '. 'D://Paper/aaa.doc');//这里的路径要写绝对路径!!!
$newfile = 'D://Paper/aaa.txt';
if(is_file($newfile)) {
continue;
}
var_dump($content);
echo "转换完成\n\t";