michaeln82 Posted September 6, 2008 Share Posted September 6, 2008 Hello, I want to be able to store all of my email templates for my website in my DB. Question is: When I pull out one of these templates from my DB, it's going to have $variable's in them. How to I tell PHP to do its usual "variable substitution" on the string? To test I tried: $a = 1; $c = '$a more time!'; echo "$c <br />"; No such luck. Any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/123063-string-variable-substitution/ Share on other sites More sharing options...
.josh Posted September 6, 2008 Share Posted September 6, 2008 single quotes do not parse variables. Quote Link to comment https://forums.phpfreaks.com/topic/123063-string-variable-substitution/#findComment-635506 Share on other sites More sharing options...
michaeln82 Posted September 6, 2008 Author Share Posted September 6, 2008 I understand that. The point of using single quotes is to see if there is any way, after $a has already been defined (with no substitutions), I am able to make PHP substitute variables in the string. In reality, I'll be pulling the string out of my DB. Quote Link to comment https://forums.phpfreaks.com/topic/123063-string-variable-substitution/#findComment-635507 Share on other sites More sharing options...
.josh Posted September 6, 2008 Share Posted September 6, 2008 perhaps eval is what you are looking for? Quote Link to comment https://forums.phpfreaks.com/topic/123063-string-variable-substitution/#findComment-635510 Share on other sites More sharing options...
michaeln82 Posted September 6, 2008 Author Share Posted September 6, 2008 Perfect! :-D Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/123063-string-variable-substitution/#findComment-635512 Share on other sites More sharing options...
thebadbad Posted September 6, 2008 Share Posted September 6, 2008 A bit late: You could eval() the code, but if you do, be absolutely certain that no (unverified) user data gets eval()'ed. As long as it's explicitly your own code, you should be okay. Try this example: <?php $a = 1; $c = '$a more time!'; eval("echo \"$c\";"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/123063-string-variable-substitution/#findComment-635514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.