PHP Read doc file

Source: Internet
Author: User
There was a problem with PHP reading the doc file.
Baidu installed third-party package to achieve
System Hint * * is not a Word document ....
Help

Reply content:

There was a problem with PHP reading the doc file.
Baidu installed third-party package to achieve
System Hint * * is not a Word document ....
Help

You can use Phpword to make sure that your PHP version is PHP 5.3+

if ($ext = = ' docx ') {
docx files can be read directly
$contents = $this->extracttext ($file);
}elseif ($ext = = ' Doc ') {
Doc file, you need to install Antiword software to read
$contents = Shell_exec ("antiword-m UTF-8 $file");
}else{
$contents = file_get_contents ($file);
}

 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;}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.