I'm storing text in a database field that is later pulled out using PHP and displayed in an html page. Basic "dynamic page" stuff so far. But I would also like to store variable names in the text and have those variable names replaced with their actual values which are set in PHP at the top of the page. Example text from database: "You have $vacdays days of vacation" would turn into "You have 21 days of vacation" if I set $vacdays=21 at the top of the page. Is there a way to do this other than search-and-replace?
Thanks you in advance for your response,
David Rock
Variable names in text?
Moderator: General Moderators
Unfortunately when I store that text in the database and pull it back out and display it, I'm seeing $vacdays or '.$vacdays.' (literally) rather than the current value of $vacdays from PHP. If I simply use: print "You have $vacdays days of vacation"; in my .php page, it works the way I want. But when I store that same text in a database then pull it out and assign it to $variablename and print $variablename; it does not convert $vacdays to the current value of $vacdays from PHP. There must be a slick way to do this...
Thanks
Thanks
Hi,
Use the 'eval' function on the string you returned from the database. See the PHP documentation for how to do this:
http://www.php.net/manual/en/function.eval.php
Andy
Use the 'eval' function on the string you returned from the database. See the PHP documentation for how to do this:
http://www.php.net/manual/en/function.eval.php
Andy