Page 1 of 1
Is it possible to store eval() results in a variable?
Posted: Fri Aug 27, 2004 5:27 pm
by liminalhigh
I have a mix of HTML/PHP stored in mysql as a template. I run eval() to populate the variables from the template. I can get it to display/view properly, however I want to take the actual final, evaluated HTML and email it to myself.
It seems like all I would need to do is store the eval()'d code in a variable, and then include it in the basic mail() function.
Is this even possible? Is there some other way of doing this?
Thanks!
Posted: Fri Aug 27, 2004 5:34 pm
by kettle_drum
Something like:
Where the php code and stuff is in the $code variable.
Posted: Fri Aug 27, 2004 5:50 pm
by liminalhigh
Heyas,
I just tried this and for some reason it doesn't actually evaluate the code... just spits out the HTML/PHP from the db. :\
Posted: Fri Aug 27, 2004 5:53 pm
by feyd
because you have it echoing out... [php_man]ob_start[/php_man]
Posted: Fri Aug 27, 2004 6:14 pm
by liminalhigh
Sorry, but I don't get it. I'm not actually using echo anywhere... I am just trying to fit $variable into the mail() function:
for example:
Code: Select all
<?php
eval("\$strBody = \$template;");
mail ($strMailTo, $strSubject, $strBody, $strXHeaders);
?>
Posted: Fri Aug 27, 2004 6:34 pm
by feyd
if you jump in and out of php inside this code, you have it echoing out. you need to capture it, via output buffering (ob_start)
Posted: Tue Aug 31, 2004 5:58 am
by ldomingues
Can you post an exemple of what you have in $template ?
Posted: Tue Aug 31, 2004 7:52 am
by McGruff
Eval is a code smell. You rarely need it, and if you do you're probably doing something the wrong way.
I'd suggest storing templates as html files rather than in the db. That'll remove any need for eval as well as allowing you to open the html files in a wysiwyg editor or etc.