需要先安装com 扩展,若没有 百度下载,注意 需要转换处理下字符
php.ini 添加
extension=php_com_dotnet.dll
com.allow_dcom = true
//--------------------------------------------------------------------------------------------------------------
header("Content-type:text/html;charset=utf-8");
$filename = "./test.docx";
$word = new COM("word.application") or die("Can’t start Word!");
//echo "Loading Word, v. {$word->Version}";
$word->Documents->open(dirname(__FILE__)."/test.docx");
$str= $word->ActiveDocument->content->Text;
$str= iconv('GB2312', 'UTF-8', $str);
preg_match_all('((https?|ftp|gopher|telnet|file|notes|ms-help):'.'((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)',
$str, $matches, PREG_PATTERN_ORDER);
echo "-----------------------------------------------------------------------";
echo "<br/>";
if($_GET['s']){
$count=substr_count($str,$_GET['s']);
echo $_GET['s']." 出现了:".$count."次";
}
echo "<br/>";
echo "-----------------------------------------------------------------------";
echo "<br/>";
//var_dump( ($matches));die;
foreach($matches[0] as $v){
var_dump($v); echo '<br/>';
}
echo "<br/>";
echo "-----------------------------------------------------------------------";
die;