george 1 Posted October 15, 2013 Report Share Posted October 15, 2013 How can I save a little PHP code to $Tom, and then evaluate $Tom and save that to a variable as attempted below:? $Tom = "echo 'blah'"eval($Tom); When I try and use eval here, I get the following error: Parse error: syntax error, unexpected $end, expecting ',' or ';' Worse still, I want to save the result of eval to an array element. as for saving the value to an array, I tried $bob = eval($Tom);and array_push($myarray, $varone, "'".eval($Tom)."'") Didn't work. I am very frustrated with eval. How can I do what I am trying to do? That is, save the result of eval to an array element? I did a search on eval, and got a lot of suggestions and saw lots of requests for a replacement function, but the suggestions were what I have seen before, and did not know how to apply, and the requests for a replacement function went unanswered. Thanks You guys are great. Quote Link to post Share on other sites
niche 141 Posted October 15, 2013 Report Share Posted October 15, 2013 Where's your semicolon? http://www.w3schools.com/php/func_misc_eval.asp Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 15, 2013 Report Share Posted October 15, 2013 Did you check the manual? http://www.php.net/manual/en/function.eval.php The notes describe using a return statement inside the evaluated code to return a value, otherwise eval returns null. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.