[SOLVED] need php eval help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jiggy1com
Forum Newbie
Posts: 6
Joined: Sun Jul 11, 2004 11:55 pm
Location: orange county, ca

need php eval help

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
jiggy1com
Forum Newbie
Posts: 6
Joined: Sun Jul 11, 2004 11:55 pm
Location: orange county, ca

thanks

Post 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]
Post Reply