Jump to content

String variable substitution


michaeln82

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/123063-string-variable-substitution/
Share on other sites

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.

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\";");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.