php实现获取word中的内容
php实现获取word中的内容
<?php
function listDir() {
$dirs=glob("*.docx");
return $dirs;
}
function getDocumentContent($path){
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath($path));
// Extract content.
$content = (string) $word->ActiveDocument->Content;
$encode = mb_detect_encoding($content, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
//echo $encode.PHP_EOL;
$content = mb_convert_encoding($content, 'UTF-8', $encode);
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
return $content;
}
$dirs=listDir();
foreach ($dirs as $dir) {
echo $dir.PHP_EOL;
echo "++++++++++++++++++++".PHP_EOL;
$content=getDocumentContent($dir);
echo $content;
}
?>