Home > Backend Development > PHP Tutorial > PHP读取DOC 文件

PHP读取DOC 文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:39:14
Original
3023 people have browsed it

PHP读取DOC文件时出问题。
百度的安装第三方包 来实现
系统提示 ** is not a word document....
求助

回复内容:

PHP读取DOC文件时出问题。
百度的安装第三方包 来实现
系统提示 ** is not a word document....
求助

可以使用一下PHPWord,要确保你的php版本是 PHP 5.3+

if($ext == 'docx'){
//docx文件可以直接读取
$contents = $this->extracttext($file);
}elseif($ext == 'doc'){
//doc文件,需要安装antiword软件来读取
$contents = shell_exec( "antiword -m UTF-8 $file" );
}else{
$contents = file_get_contents($file);
}

<code> function extracttext($filename) {
    $ext = end(explode('.', $filename));
    if($ext == 'docx')
        $dataFile = "word/document.xml";
    else
        $dataFile = "content.xml";
    $zip = new ZipArchive;
    if (true === $zip->open($filename)) {
        if (($index = $zip->locateName($dataFile)) !== false) {
            $text = $zip->getFromIndex($index);
            $xml = DOMDocument::loadXML($text, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
            return strip_tags($xml->saveXML());
        }
        $zip->close();
    }
    return false;
}
</code>
Copy after login
Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template