$var = "1+2+3+4+5"; // should be 15
eval('$result = ('.$var.');');
echo $result; // returns 15
---
could also be written as:
eval("\$result = ($var);");but that's not the point ;) Whitehawk Stormchaser wrote:
Hi!
I have been trying to make some sort of calculator in PHP, but I have stumbled on a problem... I have been make some kind of dynamical calculator, unlike most I have seen, that had $value1 [math operator] $value2 strict, but a calculator, that can calculate basically anything ( even something like (5*(8-3)+2*(4-1))^3 ), and can be put in as string variable...
I have tried things like this:
$var = "1+1+1+1"; echo $var + 0; //returns 1
or
$var = "1+1+1+1"; echo eval("\$var;"); //returns blank
or
$var = "1+1+1+1"; echo (int) $var; //returns 1
things like that...
Now my question is: is it possible to calculate the value of the string somehow?
Thanks. Stormy.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

