Jump to content

PHP - How to read MS-Word doc


KiranKumar

Recommended Posts

the method i use is very similar to what jitesh mentions. without knowing the exact file format's structure, it's very hit and miss - if it's important to keep the formatting in tact, then you're going to struggle a bit unless you're prepared to get down and dirty and do some serious homework.

 

in addition to jitesh's code, put this line:

 

$header = fread($handle, 2560);

 

just before the $contents = fread() line, which will read off the first 2560 bytes (which is essentially the header and useless without knowing what to do with it...)

 

what you're left with then (in $contents) is the plain text with various formatting characters (ie, the 'Junk' you mention). a series of str_replace / preg_replace will deal with these.

 

there are programs such as antiword / catdoc, etc you can google for (both free) which will take the headache out of it, but like i say - if you want it to appear in your browser as it would in MS Word itself, then you'd need a plugin for your browser, rather than anything specifically PHP

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.