Page 1 of 1

read ms-word rtf/doc into variable - change data - then outp

Posted: Thu Apr 26, 2007 6:38 pm
by alltimefav
I can get my PHP 5 code to read text into a file but NOT msword or .rtf

opening the document works fine also

here's the code

$ht = file( '/pathtotemplate/contract1.htm' );
$ht = implode( '', $ht ); // don't know what this is for

// substitute stuff here in the original rtf or doc file (works on html data but not rtf or doc)
$ht = str_replace("[[longdate]]",$ld,$ht);

header("Content-Type: application/msword");
header("Content-Disposition: filename=\"myfile.rtf\"" );
header("Pragma: no-cache");
header("Expires: 0");

print $ht;

exit;

Posted: Fri Apr 27, 2007 8:41 am
by alltimefav
using an HTML template works fine

$ht = file( '/pathtotemplate/contract1.htm' );

output works to screen in html

using this does not (rtf file stored as text on my server)

$ht = file( '/pathtotemplate/contract1.rtf' );

output = blank

Posted: Fri Apr 27, 2007 8:56 am
by Kieran Huggins
open a word file in notepad and take a look at it - that's what you're dealing with in PHP.

Posted: Fri Apr 27, 2007 9:35 am
by alltimefav
With RTF though it is just a "text" file.