Re: math in PHP

From: Date: Mon, 20 Sep 2004 07:12:42 +0000
Subject: Re: math in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197253@lists.php.net to get a copy of this message
<?php $var = "1+1+1+1"; eval("echo $var;"); // return 4 // OR eval("\$res = $var;"); echo $res; // return 4 also ... ?> -Hatem ----- Original Message ----- From: "Whitehawk Stormchaser" <zerokode@gmx.net> To: <php-general@lists.php.net> Sent: Saturday, September 18, 2004 11:15 PM Subject: [PHP] math in PHP > 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 >

« previous php.general (#197253) next »