Page 1 of 1

need php eval help

Posted: Sun Jul 11, 2004 11:55 pm
by jiggy1com
trying to use eval() for php but am having difficulties figuring out its syntax, or maybe using the wrong function

in CF i can do this:

Code: Select all

<cfset x='abc'>
<cfset y='2'>
<cfset z='3'>
<cfoutput>
#x# is the same as #evaluate(x)#
and
#abc_2# is the same as #evaluate(x & '_' & '2')#
<!--- The value of 'abc_2' is output the same regardless of method used --->
</cfoutput>
How is the evaluate(x & '_' & '2') expression created in PHP ?
(x is a variable, _ and 2 are known strings)

im sure there is an easy fix, maybe im just tired!

Thanks,

- Joe


feyd | Please use

Code: Select all

tags when non-php code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Jul 12, 2004 12:14 am
by feyd

Code: Select all

<?php

$abc_2 = 'some variable';
$x = 'abc';
$y = '2';
$z = $x.'_'.$y;

echo eval("return \${$x}_{$y};")."\n";
echo $$z;

?>
outputs

Code: Select all

some variable
some variable

thanks

Posted: Mon Jul 12, 2004 10:57 am
by jiggy1com
thanks for your help, it works and i successfully modified it to work with what i need. i also read up on how to properly post code (my apologies)[/php_man]