Re: interpreting variables containing in another variable
| From: | Ernest E Vogelsinger | Date: | Wed, 20 Nov 2002 21:32:25 +0000 |
| Subject: | Re: interpreting variables containing in another variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125333@lists.php.net to get a copy of this message | ||
At 19:15 20.11.2002, ROBERT MCPEAK said:
--------------------[snip]--------------------
>I've got a variable - $email_body, that contain's other variables. For
>example, echo "$email_body," might look like this:
>
>$name, $address, $phone, $blah
>
>
>I want those variables to interpreted with corresponding values set earlier
>in the script. So, in effect, where name=bob, address=101 east main,
>phone=555-5555, and blah=foo, echo "$email_body" would look like this:
>
>bob, 101 east main, 555-5555, foo
--------------------[snip]--------------------
That's what eval() is for. eval() evaluates syntactically correct PHP code.
What you need to do is
$email_body = str_replace('"', '\"', $email_body);
global $php_error;
$php_error = null;
@eval("\$email_body = \"$email_body\";");
if ($php_error) die ($php_error);
Of course all double quotes need to be escaped beforehand, as the example
shows. The error handling here is somewhat useless but demonstrates the idea.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/