Re: eval help
| From: | neko | Date: | Mon, 03 Mar 2003 14:35:11 +0000 |
| Subject: | Re: eval help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137893@lists.php.net to get a copy of this message | ||
Actually, I just realised that what I want to accomplish is different from
my example - the main issue is with scope:
<?php
/*
eval testing 3
SM 33/3/2003 2:32PM
*/
func1();
function func1()
{
echo("<br>we're in the pipe, 5-5-5.");
$str = "<br>Hello, \$name";
$str2 = "<br>Hello, \$arr[0]";
$str3 = "<br>Hello, \$arr2['name']";
echo doEvalWithVarsInScope($str);
echo doEvalWithVarsInScope($str2);
echo doEvalWithVarsInScope($str3);
}
function doEvalWithVarsInScope($str)
{
echo("<br>trying to eval for str=$str");
$name = "Scott";
$arr[] = "Dude";
$arr2["name"] = "Broness!";
eval ("\$evaldString = \"$str\";");
return $evaldString;
}
?>
--
will produce:
we're in the pipe, 5-5-5.
trying to eval for str=
Hello, $name
Hello, Scott
trying to eval for str=
Hello, $arr[0]
Hello, Dude
trying to eval for str=
Hello, $arr2['name']
Hello,
--
any (more) help is greatly appreciated.
cheers,
neko