?
Solved

STR_REPLACE with PHP and RTF

Posted on 2003-03-06
2
Medium Priority
?
1,396 Views
Last Modified: 2012-08-13
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
Comment
Question by:gnacer2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
Jonza earned 200 total points
ID: 8086188
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
 
LVL 1

Expert Comment

by:Jonza
ID: 8086200
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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question