PHP: Evaluating variable in string, and then changing value of variable -


i have string such following:

$s1 = "apples"; $s2 = "$s1 great"; echo $s2; 

my understanding of php double-quotes in second line cause $s1 evaluated within string, , output be

apples great 

however, if wanted keep $s2 "template" change $s1's value , re-evaluate new string? possible? example:

$s1 = "apples"; $s2 = "$s1 great"; echo $s2 . "\n";  $s1 = "bananas"; $s3 = "$s2"; echo $s3 . "\n"; 

i find output following is:

apples great  apples great 

what hoping more like:

apples great  bananas great 

is such thing possible php can keep "template" string same, change input variables, , reevaluate new string? or not possible php?

well, this: (just quick mashup).

$template = "{key} great"; $s1 = "apples"; $s2 = "bananas";  echo str_replace('{key}',$s1,$template) . "\n"; echo str_replace('{key}',$s2,$template) . "\n"; 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -