Joonake Posted July 16, 2010 Share Posted July 16, 2010 Hello all, I have a problem when I am trying to create calculator with PHP. I have created form that you can use to add numbers and operations to input field, but I just cant figure out how to "calculate" the calculation that is stored in variable. For example: $expression = "5"; $expression .= "+"; $expression .= "5"; $answer = $expression; This way I get just the "5+5" on $answer, but I would like to get "10". I dont want to write my own function to parse the calculation because I know that it exists, just dont know how this is done. I have tried to use printf but it wont help. Anyone can help me? Quote Link to comment https://forums.phpfreaks.com/topic/207938-calculating-expression-from-variable/ Share on other sites More sharing options...
Daniel0 Posted July 16, 2010 Share Posted July 16, 2010 Why don't you try to search this board? This question has been asked many times. Quote Link to comment https://forums.phpfreaks.com/topic/207938-calculating-expression-from-variable/#findComment-1087008 Share on other sites More sharing options...
Joonake Posted July 16, 2010 Author Share Posted July 16, 2010 Why don't you try to search this board? This question has been asked many times. Tried to search but dont find anything. I just cant find proper keywords for this :'( Quote Link to comment https://forums.phpfreaks.com/topic/207938-calculating-expression-from-variable/#findComment-1087018 Share on other sites More sharing options...
Alex Posted July 16, 2010 Share Posted July 16, 2010 Check out this topic: http://www.phpfreaks.com/forums/index.php/topic,295366.0.html Quote Link to comment https://forums.phpfreaks.com/topic/207938-calculating-expression-from-variable/#findComment-1087114 Share on other sites More sharing options...
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.