antiword implements php to read word content phpword implements word write

Reprinted from: https://blog.csdn.net/zhoubl668/article/details/53743145

1: Antiword implements php to read word content

      PHP does not come with a class or library for reading word files. Here we use the antiword ( http://www.winfield.demon.nl/ ) package to read doc files.

     First introduce how to use it under Windows:

      1. Open http://www.winfield.demon.nl/ (antiword download page), find the corresponding windows version ( http://www.winfield.demon.nl/#Windows ), and download the antiword windows version ( antiword- 0_37-windows.zip );

      2. Unzip the downloaded file to the root directory of the C drive;

There is another point to note here: http://www.informatik.uni-frankfurt.de/~markus/antiword/00README.WIN This link contains the instructions for installing under Windows.

  Need to set environment variables, My Computer (right click)->Advanced->Environment Variables->Create a new one in the above user variables

  Variable name: HOME

  Variable value: The c:\home directory should exist, if not, create a home folder under the C drive.

  Then in the system variable, modify the Path, and add %HOME%\antiword in front of the value of the Path variable;

 

      3. Start -> Run -> CMD to enter the antiword directory;

      Enter antiword -h to see the effect.

 

   4. Then we use the antiword –t command to read the content of the doc file; first copy a doc file to the c:\antiword directory, and then execute

   >antiword –t filename.doc

   You can see the contents of the output word file on the screen.

 Code

 

public function phpword()
    {
        $ locale = 'en_US.UTF-8';
        setlocale(LC_ALL,$locale);
        putenv('LC_ALL='.$locale);
        $file = 'c:\antiword\ww.doc';
        $content = shell_exec('c:\antiword\antiword –f ' . $file . ' ');
        dd($content);
    }

Due to the encoding format of the read file format, first set the encoding format of the shell_exec function to UTF-8


In this way, the content in the word is read into the content.

As for how to read the content of the doc file under Linux, it is to download the compressed package of the Linux version, which contains the readme.txt file, and install it in that way.


$content = shell_exec ( "/usr/local/bin/antiword -f $file" );


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325898214&siteId=291194637