read ms word file from php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dev_mohamed
Forum Newbie
Posts: 2
Joined: Tue Dec 16, 2008 4:34 pm

read ms word file from php script

Post by dev_mohamed »

Dear all,

i have this php code which read ms word file, the problem is that the .doc file is not plain text, the script read the .doc file but is also get many special char which is not needed i need the word content only i also will run this script on linux server so i must not use the COM object

$userDoc = "rev.doc";

function parseWord($userDoc)
{
$fileHandle = fopen($userDoc, "r");
$line = @fread($fileHandle, filesize($userDoc));
$lines = explode(chr(0x0D),$line);
$outtext = "";
foreach($lines as $thisline)
{
$pos = strpos($thisline, chr(0x00));
if (($pos !== FALSE)||(strlen($thisline)==0)) { }
else { $outtext .= $thisline." "; } }
$outtext = preg_replace("/[^a-zA-Z0-9\s\,.\n\r\t@\/_()]/","",$outtext);
return $outtext;
}

$text = parseWord($userDoc);
echo $text;

it get the content but after this it print the bad data like the next i need the word data only


Word.Picture.8 DDSr2D6qFXt1tFDxJih8FDDpnFODWZgu3l4XJQDd F(EZmt)1WlLrOoGNmED2xq2Dcm9W_jEDnnIauElLv43Qo/M4I4I52DU2tqRMlnSDDNIkx@v22DS4DDnMuQxfoWfMP4tf .Xyd ) XDL.sq nREfr gU o vnPDTcnrc7pyPrK)UnbfRImNIKbikBff@neEn wk_sSpRXg6dvd_v_/czqnWS/lzHZ2OAZYvEZNEd6mhwc6QVipe1ec5c9FAWUZk5n M7eLRsSiFYolJ MyCfoUaY3D5fP/dn9v ivWs qXkt9)7nM GthIvFv.A A)xOe/17yzo0tCnoVO wsNubtRqMo6BmK ,.AGt jcc 9p.OWnRd 8jDrIPsjW1I.Qbq VA7U3lu.
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: read ms word file from php script

Post by The_Anomaly »

Quick google turned this up. Never tried it though.
Post Reply