How to read doc files in php

In this tutorial I’m going to show you how to read .doc files in php. Doc files are files that are made using Microsoft Word if you’re on Windows. And Open Office if you’re on Linux.


First you have to extract the contents of the zip archive into your project folder. Rename the extracted folder to antiword if it isn’t already named antiword.

From the antiword folder, copy the file named  8859-1.txt and paste it on:


Just create an antiword folder directly under c: drive or where Windows is installed if its not created yet.

Next, just paste in the code below, and edit it to match your configuration. Note that tuts.doc in the example below is adjacent to the php script. But you can also change that if you want a separate folder for doc files alone. The –f parameter will just format the output. It will wrap words that are bold with * * and italics with / /. I’m still yet to figure out how to convert those into actual html.

<?php $filename = 'tuts.doc'; $content = shell_exec('C:wampwwwtesterread_documentsantiwordantiword -f '.

$filename); echo $content; ?>

Here’s a sample output, as you can see it’s a little messy:


And not just little, I think its really messed up. Compared to the result in the command line:


I won’t put any conclusion on this tutorial. I really think its incomplete. So if ever you know how to format the result of the script then please shout them out in the comments below.

1 thought on “How to read doc files in php

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s