george Posted October 15, 2013 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. Link to comment Share on other sites More sharing options...
niche Posted October 15, 2013 Share Posted October 15, 2013 Where's your semicolon? http://www.w3schools.com/php/func_misc_eval.asp Link to comment Share on other sites More sharing options...
justsomeguy Posted October 15, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now