在PHP中读取DOC文件 [英] Reading DOC file in php

查看:207
本文介绍了在PHP中读取DOC文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取php中的.doc .docx文件.一切正常.但是在最后一行,我遇到了可怕的角色.请帮我. 这是某人开发的代码.

I'm trying to read .doc .docx file in php. All is working fine. But at last line I'm getting awful characters. Please help me. Here is code which is developed by someone.

    function parseWord($userDoc) 
{
    $fileHandle = fopen($userDoc, "r");
    $line = @fread($fileHandle, filesize($userDoc));   
    $lines = explode(chr(0x0D),$line);
    $outtext = "";
    foreach($lines as $thisline)
      {
        $pos = strpos($thisline, chr(0x00));
        if (($pos !== FALSE)||(strlen($thisline)==0))
          {
          } else {
            $outtext .= $thisline." ";
          }
      }
     $outtext = preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/","",$outtext);
    return $outtext;
} 

$userDoc = "k.doc";

这是屏幕截图.

推荐答案

DOC文件不是纯文本.

尝试使用诸如 PHPWord ( nb:由于PHPWord更改了托管和功能,此答案已多次更新.

nb: This answer has been updated multiple times as PHPWord has changed hosting and functionality.

这篇关于在PHP中读取DOC文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆