Forum Moderators: coopster

Message Too Old, No Replies

Changing a template with an array

How to replace values in a template with variables

         

dougmcc1

5:12 am on Jul 17, 2003 (gmt 0)

10+ Year Member



This array takes input from a form and inserts it in a template:

$fields_to_parse=array("string1","string2","string3");

while (list($null,$field)=each($fields_to_parse)) {
$template=str_replace("[[".$field."]]",strip_tags($_POST[$field]),$template);
}

So if I enter 'Foo' into <input name="string1">, then in the template [[string1]] is replaced with 'Foo'.

How do I acheive the same effect with variables instead of form input?

I want to be able to replace [[string1]] with $string1.
Thanks.

vincevincevince

8:33 am on Jul 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$template=str_replace("[[string1]]",$string1,$template);
$template=str_replace("[[string2]]",$string2,$template);
$template=str_replace("[[string3]]",$string3,$template);

dougmcc1

10:37 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



Short and sweet :)

Thanks vince.