Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.