[Phpwm] Fnuction to calculate a formula

Rob Allen rob at akrabat.com
Tue Dec 4 06:09:40 GMT 2007


On 3 Dec 2007, at 19:43, Colin Taylor wrote:

> Hello,
> I am on the hunt for a PHP 5 function that will calculate a given  
> formula.
> For example:
>
> $formula="2+2";
> $result=calculate_formula($formula);
> echo "$formula = $result";
>
> Would reult in:
>
> 2+2 = 4

eval() is about the only way to do it as far as I know. I'd start with  
Smarty's math function for ideas:

http://viewcvs.php.net/viewcvs.cgi/smarty/libs/plugins/function.math.php?view=markup


Regards,

Rob...




More information about the Phpwm mailing list