• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1437
  • Last Modified:

STR_REPLACE with PHP and RTF

Ok, so I have a program that generates values that will be used to populate a RTF template.  For example, a script creates the values $sub_total, $tax, and $total.  In the RTF template that I am using, I have the placeholders setup as <<SUB>>, <<TAX>> and <<TOTAL>>.  I want a way to go through the entire RTF file and replace the PHs with the correct values.  I saw in another question the following answer:

$file_contents = join('',file('test.rtf'));
$output = str_replace('<<SUB>>',$sub_total,$file_contents);
$output = str_replace('<<TAX>>',$tax,$file_contents);
$output = str_replace('<<TOTAL>>',$total,$file_contents);

Header("Content-type: application/msword");
Header("Content-Disposition: attachment;filename=anything.doc");

echo $output;

But when I use that, it only replaces one PH and the others just remain.  It seems to only replace the last var (<<TOTAL>>).  Can someone help?
0
gnacer2001
Asked:
gnacer2001
  • 2
1 Solution
 
JonzaCommented:
try this:
----------------------------------------------------------
$file_contents = join('',file('test.rtf'));
$output = str_replace('<<SUB>>',$sub_total,$file_contents);
$output = str_replace('<<TAX>>',$tax,$output);
$output = str_replace('<<TOTAL>>',$total,$output);

Header("Content-type: application/msword");
Header("Content-Disposition: attachment;filename=anything.doc");
----------------------------------------------------------
0
 
JonzaCommented:
you had a problem with your variables.

once you replace the PHs and put the whole file to output variable you have to replace the others at output variable, not the file_contents..
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now