zoukankan      html  css  js  c++  java
  • linux下如何用php读取word

    在实际的工作中遇到到要导入word格式的文件,经过努力,终于成功了。

    在linux上用PHP读取WORD文档,其实是使用了 antiword程序把word文档转化为txt文档。

    再使用php执行系统命令调用而已。

    具体操作如下:

    1、安装antiword

    官方站:http://www.winfield.demon.nl/

    下载地:http://www.winfield.demon.nl/linux/antiword-0.37.tar.gz

    下载完,解压,进入目录

    使用命令 make && make install

    即可完成安装。

    安装时,自动安装到了/root/目录下,只有root才可执行该命令,我们需要改一下路径,COPY到/usr中方便调用。

    cp /root/bin/*antiword /usr/local/bin/
    mkdir /usr/share/antiword
    cp -R /root/.antiword/* /usr/share/antiword/
    chmod 777 /usr/local/bin/*antiword
    chmod 755 /usr/share/antiword/*

    以上操作以后即可在任意用户调用 antiword命令。

    然后编写php脚本:

    PHP代码
    1. $content = shell_exec('/usr/local/bin/antiword '.$filename);  

    即可读入文件内容。如果中文码乱,再加上编码即可:

    PHP代码
    1. $content = shell_exec('/usr/local/bin/antiword -m UTF-8.txt '.$filename);  

    现在你可以在PHP中任意处理内容了。

    在使用的过程中发现了个小小的问题,就是在默认情况下antiword生成的文本把doc中的换行都改成了硬回车,明显有点多余……
    用-h看了看,发现只须在“antiword”命令后"-w 0"(-w为设置行宽,0即无限制)便可解决问题……

     
    原文:http://yuninglovekefan.blog.sohu.com/265046985.html
  • 相关阅读:
    Ultra-QuickSort(归并排序求逆序对数)
    Power Network (最大流增广路算法模板题)
    Sorting It All Out
    Asteroids(二分图最大匹配模板题)
    昂贵的聘礼
    Borg Maze(bfs+prim)
    Currency Exchange(判断是否有正环)
    Children of the Candy Corn (bfs+dfs)
    Tautology
    Flip Game
  • 原文地址:https://www.cnblogs.com/zjdeblog/p/7099355.html
Copyright © 2011-2022 走看看