如何用PHP在Linux系统上读取Word文档?

2026-04-02 03:191阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计406个文字,预计阅读时间需要2分钟。

如何用PHP在Linux系统上读取Word文档?

请提供需要改写的伪原创开头内容,我会根据您的要求进行修改。

#wget www.winfield.demon.nl/linux/antiword-0.37.tar.gz
#tar zxvf antiword-0.37.tar.gz
#cd antiword-0.37
#make
#make install

antiword
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/*

安装完成之后,如果要在web上查看的话,需要使用root执行 makeglobal_install+


<?php header("Content-type: text/html; charset=utf-8"); $filename = 'test.doc'; #$content = shell_exec('/usr/local/bin/antiword '.$filename); $content = shell_exec('antiword -mUTF-8 '.$filename); echo '<pre>'; print_r ($content); echo '</pre>';


shell上测试使用

  1. /usr/local/bin/antiword 你的word文档
  2. #如果中文码乱,再加上编码
  3. /usr/local/bin/antiword -w0-m UTF-8.txt 你的word文档
  4. #需要注意,word文档内容太少会提示: I’m afraid the text stream of this file is too small to handle.


如何用PHP在Linux系统上读取Word文档?

php上使用

  1. $filename =‘你的word文档’;
  2. $content = shell_exec(‘/usr/local/bin/antiword -w 0 -m UTF-8.txt ‘.$filename);
  3. //将串中所有可能的全角符转为半角符
  4. //全角
  5. $DBC =Array(‘0’,‘1’,‘2’,‘3’,‘4’)
  6. // 半角
  7. $SBC =Array(‘0’,‘1’,‘2’,‘3’,‘4’)
  8. $content = str_replace($DBC, $SBC, $str); // 全角到半角
  9. var_dump($content);

本文共计406个文字,预计阅读时间需要2分钟。

如何用PHP在Linux系统上读取Word文档?

请提供需要改写的伪原创开头内容,我会根据您的要求进行修改。

#wget www.winfield.demon.nl/linux/antiword-0.37.tar.gz
#tar zxvf antiword-0.37.tar.gz
#cd antiword-0.37
#make
#make install

antiword
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/*

安装完成之后,如果要在web上查看的话,需要使用root执行 makeglobal_install+


<?php header("Content-type: text/html; charset=utf-8"); $filename = 'test.doc'; #$content = shell_exec('/usr/local/bin/antiword '.$filename); $content = shell_exec('antiword -mUTF-8 '.$filename); echo '<pre>'; print_r ($content); echo '</pre>';


shell上测试使用

  1. /usr/local/bin/antiword 你的word文档
  2. #如果中文码乱,再加上编码
  3. /usr/local/bin/antiword -w0-m UTF-8.txt 你的word文档
  4. #需要注意,word文档内容太少会提示: I’m afraid the text stream of this file is too small to handle.


如何用PHP在Linux系统上读取Word文档?

php上使用

  1. $filename =‘你的word文档’;
  2. $content = shell_exec(‘/usr/local/bin/antiword -w 0 -m UTF-8.txt ‘.$filename);
  3. //将串中所有可能的全角符转为半角符
  4. //全角
  5. $DBC =Array(‘0’,‘1’,‘2’,‘3’,‘4’)
  6. // 半角
  7. $SBC =Array(‘0’,‘1’,‘2’,‘3’,‘4’)
  8. $content = str_replace($DBC, $SBC, $str); // 全角到半角
  9. var_dump($content);