I created .doc file using html tags, which is having HTML form elements like Textbox, checkbox, radiobutton, dropdown and hidden fields. Those are showing properly when opening the document.
- I am able parse the .doc file when updated the .doc file with php code. And able to use the form fileds data when saving into Database.
- When using the 'Save As' option in the .doc file, the newly created doc file showing the html form elements properly. But unable to parse data from the 'Save As' file.
I want to parse the 'Save As' doc file also using php. Please help me how could i resolve this issue?
Here is my doc file parsing code:
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." ";
}
}
if(trim($outtext)==""){
$outtext ="";
//echo "<br> UTF ";
$filename = $userDoc;
if ( file_exists($filename) ) {
$outtext ="";
if ( ($fh = fopen($filename, 'r')) !== false ) {
$headers = fread($fh, 0xA00);
# 1 = (ord(n)*1) ; Document has from 0 to 255 characters
$n1 = ( ord($headers[0x21C]) - 1 );
# 1 = ((ord(n)-8)*256) ; Document has from 256 to 63743 characters
$n2 = ( ( ord($headers[0x21D]) - 8 ) * 256 );
# 1 = ((ord(n)*256)*256) ; Document has from 63744 to 16775423 characters
$n3 = ( ( ord($headers[0x21E]) * 256 ) * 256 );
# (((ord(n)*256)*256)*256) ; Document has from 16775424 to 4294965504 characters
$n4 = ( ( ( ord($headers[0x21F]) * 256 ) * 256 ) * 256 );
# Total length of text in the document
$textLength = ($n1 + $n2 + $n3 + $n4);
$extracted_plaintext = fread($fh, $textLength);
# if you want the plain text with no formatting, do this
//echo $extracted_plaintext;
$outtext .= $extracted_plaintext;
# if you want to see your paragraphs in a web page, do this
//echo nl2br($extracted_plaintext);
}
fclose($fh);
}
}
$outtext = preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/","",$outtext);
return $outtext;
}
$userDoc = "cv.doc";
$text = parseWord($userDoc);
echo $text;
Thanks in advance...