php实现获取word中的内容

作者: admin 分类: php 发布时间: 2017-06-13 06:50

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;
}



 ?>

 

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注