<?php
/*****************************************************************
This approach uses detection of NUL (chr(00)) and end line (chr(13))
to decide where the text is:
- divide the file contents up by chr(13)
- reject any slices containing a NUL
- stitch the rest together again
- clean up with a regular expression
*****************************************************************/
function parseWord($userDoc)
{
$fileHandle = fopen($userDoc, "r");
$line = @fread($fileHandle,filesize($userDoc));
$lines = explode(chr(0x0D),$line);
$outtext = "";
$pos = strrpos($lines[1], chr(0x00));
$outtext.=substr($lines[1],$pos)."";
foreach($lines as $thisline)
{
$pos = strpos($thisline, chr(0x00));
if(($pos !== FALSE) || (strlen($thisline)==0))
{
} else {
$outtext.=$thisline."";
}
}
return $outtext;
}
$userDoc = "CreateWord2.doc";
$text = parseWord($userDoc);
echo $text;
?>