在 php 中将 .doc 转换为 html

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/253834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:04:38  来源:igfitidea点击:

Convert .doc to html in php

phphtmlms-word

提问by corymathews

Has anyone found a good class, or other file that will convert a .doc file into html or something that I can read and turn into html?

有没有人找到一个好的类,或其他文件,可以将 .doc 文件转换为 html 或我可以阅读并转换为 html 的内容?

I have been looking around for a couple hours now and have only found ones that require msword on the server in order to convert the file. I am pretty sure that is not an option but I have not actually talked to my hosting provider about it.

我已经环顾了几个小时,只找到了需要在服务器上使用 msword 才能转换文件的文件。我很确定这不是一个选项,但我实际上并没有与我的托管服务提供商讨论过这个问题。

The goal is for a user to be able to upload the file to my server and the server handle the conversion and then display it as html, much like googles view as html feature.

目标是让用户能够将文件上传到我的服务器,服务器处理转换,然后将其显示为 html,就像 googles view as html 功能一样。

回答by CronosNull

intall and use abiword, like this:

安装并使用 abiword,如下所示:

AbiWord --to=html archivo.doc

you can call this command from php.

您可以从 php 调用此命令。

回答by CronosNull

A project called phpLiveDocx does what you want. It is a SOAP based service, but can be used free of charge. For a basic introduction, please see: http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/

一个名为 phpLiveDocx 的项目可以满足您的需求。它是基于 SOAP 的服务,但可以免费使用。基本介绍请见:http: //www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/

回答by Anthony Tolman

Install open office on your system and run this on the command line:

在您的系统上安装 open office 并在命令行上运行:

/usr/bin/soffice -headless "macro:///Standard.Convert.SaveAsHtml(test.doc)"

/usr/bin/soffice -headless "macro:///Standard.Convert.SaveAsHtml(test.doc)"

回答by mvod

You can do it through openoffice with unoconv http://dag.wieers.com/home-made/unoconv/Really great tool.

您可以通过 openoffice 使用 unoconv http://dag.wieers.com/home-made/unoconv/来完成,这 真是一个很棒的工具。

回答by forever99

This PHP uploads your *.DOC file to a upload folder and opens it up in HTML.

该 PHP 将您的 *.DOC 文件上传到上传文件夹并以 HTML 格式打开它。

<?php
function content($file){
$data_array = explode(chr(0x0D),fread(fopen($file, "r"), filesize($file)));
$data_text = "";
foreach($data_array as $data_line){
if (strpos($data_line, chr(0x00) !== false)||(strlen($data_line)==0))
{} else {if(chr(0)) {$data_text .= "<br>";
                      $data_text .= preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/","",$data_line); 
       } 
   }        
}
return $data_text;}
$destination = str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']);
$destination.= "upload/";
$maxsize = 5120000;
if (isset($_GET['upload'])) {
      if($_FILES['userfile']['name'] && $_FILES['userfile']['size'] < $maxsize) {
      if(move_uploaded_file($_FILES['userfile']['tmp_name'], "$destination/".$_FILES['userfile']['name'])){
      $file = $destination."/".$_FILES['userfile']['name'];
      $data = content($file);
      echo $data;
        }   
         }
}else{
      echo "<form  enctype='multipart/form-data' method='post' action='index.php?upload'>
            <input name='userfile' type='file'>
            <input value='Upload' name='submit' type='submit'>
            </form>";
      }
?>