[PHP] interpreting variables containing in another variable

2002-11-20 Thread ROBERT MCPEAK
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-, and 
blah=foo, echo $email_body would look like this:

bob, 101 east main, 555-, foo


Any suggestions?

Thanks in advance.

-Bob


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] interpreting variables containing in another variable

2002-11-20 Thread Adam Voigt
Not sure what your saying, but like:

$email_body = $name . ,  . $address . ,  . $phone . ,  . $blah;

?

On Wed, 2002-11-20 at 13:15, ROBERT MCPEAK wrote:
 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-, and 
blah=foo, echo $email_body would look like this:
 
 bob, 101 east main, 555-, foo
 
 
 Any suggestions?
 
 Thanks in advance.
 
 -Bob
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
-- 
Adam Voigt ([EMAIL PROTECTED])
The Cryptocomm Group
My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc



signature.asc
Description: This is a digitally signed message part


Re: [PHP] interpreting variables containing in another variable

2002-11-20 Thread Chris Shiflett
--- ROBERT MCPEAK [EMAIL PROTECTED] wrote:
 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-, and blah=foo, echo $email_body would
 look like this:
 
 bob, 101 east main, 555-, foo

Check out the eval() function:

http://www.php.net/manual/en/function.eval.php

Also, you might want to consider altering your approach slightly. For
example, maybe something like this would be more appropriate:

$email_body = $name, $address, $phone, $blah;

If you echo $email_body in this case, it will output:

bob, 101 east main, 555-, foo

Good luck.

Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] interpreting variables containing in another variable

2002-11-20 Thread Ernest E Vogelsinger
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-, and blah=foo, echo $email_body would look like this:

bob, 101 east main, 555-, 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/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php