I've used this to generate invoice rtfs on a website using {TAGNAME} as the replacement value. Somtimes using string replace doesn't work, but it's just due to your tag being broken internally in the document over two lines, so just strip out all the breaks first like this...
$rtf = file_get_contents('customer-invoice.rtf');
// beautifully lazy system of knocking rtf's break a word up over multiple lines
$rtf = str_replace("\r\n", '', $rtf); // lines are broken /r/n on windows
foreach ($row as $tag => $value)
$rtf = str_replace('\{'.$tag.'\}', $value, $rtf);
header('Content-type: application/rtf');
header("Content-Disposition: attachment; filename=invoice-$row[clickid].rtf");
header('Pragma: no-cache');
header('Expires: 0');
echo $rtf;
exit;
I couldn't get it to work at all with word doc's, but did give it a go, but Word just wouldn't have it.